Geeks With Blogs
Reidar Husmo SharePoint from the trenches

I wanted to set the default termset node of a taxonomy field in a content type in a list.

(…the field should have different defaults depending on the type of library, but that's not important right now)


So. Easy. Get the list, get the content type, get the field, set the default. What could be easier?

var list = web.Lists.TryGetList("Documents"); // obvious "if"s removed

var contentType = list.ContentTypes["CT1"];

var field = contentType.Fields.GetFieldByInternalName("DocumentType") as TaxonomyField;

field.SspId = some guid


field.Update(); // KABLAM


And that's when you receive the unfortunate error that is the subject of this tiny post.

Let us skip all the wrong attempts I made at solving this, and og straight to the solution: Do not get the field from the content type - get it directly from the list instead.

var list = web.Lists.TryGetList("Documents");

var field = list.Fields.GetFieldByInternalName("DocumentType") as TaxonomyField;

It does make sense. You can only change the field on a per list (or globally) scope; you can not do it per content type.

Posted on Thursday, May 30, 2013 10:58 AM TaxonomyField , SharePoint | Back to top

Comments on this post: "This functionality is unavailable for fields not associated with a list"

# re: "This functionality is unavailable for fields not associated with a list"
Requesting Gravatar...
There is another solution for this problem:
Left by Ramūnas on Nov 14, 2013 10:03 AM

Your comment:
 (will show your gravatar)

Copyright © Norgean | Powered by: