4

I'm on a solution where I create a term with some subterms in the termstore. After that I create a sitecolumn and a listcolumn. When setting a value to the listcolumns with

 taxField.SetFieldValue(item, term, language);

taxonomyfied I get an argumentexception.

Microsoft.SharePoint.SPFieldValidationException: The given guid does not exist in the term store

The term is filled correctly and has the same guid as the element in the termstore (checked it with powershell).

What can I do to fill the newly created taxonomyfield or get around the excpetion.

[Update] It works with

taxField.SetFieldValue(item, term, language);

and the solution Stefan Bauer underneath this post. The problem is anywhere else (if you want to know read comments underneath stefan bauers post)

[Update #2] The problem was the taxonomy hidden list in the site. It was not up to date since I deleted a the field in the sitecolumns. Stefan Bauer pointed to his blogpost where the solution is first: Update your sharepoint and second: try TaxonomySession.SyncHiddenList(SPSite). Blogpost: http://www.n8d.at/blog/sharepoint-2010/anatomy-of-managed-metadata-fields/

2
  • You should add an answer to your own question based on the updates. Nov 4, 2015 at 15:41
  • Check the managed metadata site column is referencing the right group with right termset value.
    – user54560
    May 25, 2016 at 9:34

3 Answers 3

3

To set a taxonomy field you should use TaxonomyFieldValue or TaxonomiFieldValueCollection

You first need to find the term in your term store:

            TaxonomyField taxonomyField = item.Fields[field] as TaxonomyField;
            TaxonomyFieldValue taxValues = new TaxonomyFieldValue(taxonomyField);
            TaxonomySession session = new TaxonomySession(site);
            TermStore termStore = session.TermStores[taxonomyField.SspId];
            TermSet termSet = termStore.GetTermSet(taxonomyField.TermSetId);
            TermCollection terms = termSet.GetTerms(termLabel);

If you retrieved the term from the term store you can then set the value as follows

        TaxonomyFieldValue taxonomyValue = new TaxonomyFieldValue(taxonomyField);
        taxonomyValue.TermGuid = term.Id.ToString();
        taxonomyValue.Label = term.Name;
10
  • Doesn't work. I get the same error. Jun 6, 2012 at 8:58
  • This will only work if you first got the term from the Termstore. Jun 6, 2012 at 9:03
  • I've got it 2 lines above from the termstore. Jun 6, 2012 at 9:10
  • A little refactoring showed me that the function GetValidatedString() throws the error. But I just don't know why. Jun 6, 2012 at 9:11
  • I added some code how to get the term you are looking for. You also need to loop over the termcollection. Jun 6, 2012 at 9:12
0

For the error ...was not retrieved with all taxonomy fields

What others may find useful is that your Term Store field is starting at the wrong location within the Term Store. Hence the code cannot find your Term Store values as it only iterates below the Term Store field starting location which has been set.

0

The problem was the taxonomy hidden list in the site. It was not up to date since I deleted a the field in the sitecolumns. Stefan Bauer pointed to his blogpost where the solution is first: Update your sharepoint and second: try TaxonomySession.SyncHiddenList(SPSite). Blogpost: http://www.n8d.at/blog/sharepoint-2010/anatomy-of-managed-metadata-fields/

Your Answer

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

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