May 8, 2013

Error "This functionality is unavailable for fields not associated with a list" at SPField.Update()

Symptoms:

Sometimes it is necessary to modify your content type's property in a list without affecting to list items data.
The easiest way to do it is PowerShell:

$web = Get-SPWeb http://web-url
$list = $web.Lists["listName"]
$list.ContentTypes["CTName"].Fields["fieldName"].someProperty = someValue
$list.ContentTypes["CTName"].Fields["fieldName"].Update()
Oops. Error: “This functionality is unavailable for fields not associated with a list”


The reason:

SPField which is going to be modified belongs to Site Columns (SPWeb.Fields collection). Editing this SPField is unavailable.
SiteColumns are stored inside ContentTypes as FieldLinks, not as Fields.

The solution:

Use SPContentType.FieldLinks instead of SPContentType.Fields collection.
$web = Get-SPWeb http://web-url
$list = $web.Lists["listName"]
$list.ContentTypes["CTName"].FieldLinks["fieldName"].someProperty = someValue
$list.ContentTypes["CTName"].Update()
$web.Dispose()

Successfully completed without errors.

1 comment:

  1. There is another solution for this problem: http://www.ramluk.lt/en/blog.html?id=3

    ReplyDelete