2

I found this article which describes how to insert a list item that has a field which is of type TaxonomyFieldType.

The article describes how the TaxonomyFieldType is a similar type to a lookup field, and it explains the format required for the field value.

WSSID;#VAL|GUID

The VAL and GUID I can find, what I can't find is the WSSID!

Firstly let me explain what this WSSID is. For each site collection using your term store, Sharepoint creates a hidden list. In this hidden list sharepoint stores information about the managed terms IN USE in the site collection. Its important to note that just creating the term does not mean an entry will be created in this hidden list, only when the term is assigned to an item or document, then a list entry gets created. The WSSID is the list item GUID in the hidden list.

So this creates a logical problem.

I have a populated term store. I want to create items in a list (using a script and object model), and 1 column is a term from my term store (a managed field / TaxonomyFieldType )

If the term was not used before, the WSSID does technically NOT exist, so how can I get this WSSID if the term was not assigned before?

3 Answers 3

3

The other option, if you've got the field, and the Term is to use the SetFieldValue method and it's overrides, Specifically SetFieldValue(SPListItem, Term).

This will handle all the messy WssId details for you, but it assumes you've got the Term already (or Collection of Terms).

1
  • I can get the Term, so this method is looking very good. If it handles the Wssid details, then it is quicker to implement than a DIY route. thanks!
    – user879
    Dec 22, 2010 at 10:19
3

If you are trying the set the value but you don't have a Term object, you can use -1 as the WssId. SharePoint will automatically assign the correct WssId the the item.

1
  • This method works often but is not reliable. I face issues that while bulk data migration, that few items passing -1 did not work (Yes, the label and term guid were correct always :-) . I switched to the SetFieldValue method and it works 100 % time. SetFieldValue has this disadavantage that it triggers an executequery and so we cannot batch the requests
    – Unnie
    Feb 19, 2019 at 17:49
2

Did you try the static method TaxonomyField.GetWssIdsOfTerm()?

int[] wssIds = TaxonomyField.GetWssIdsOfTerm(<site>, <termStoreId>, <termSetId>,< termId>, false, 1);

Check Peter Hoplars blog post on the subject.

1
  • Aha, this looks very promising. I need to test how this works, thanks Anders.
    – user879
    Dec 21, 2010 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.