This post was most recently updated on November 30th, 2022.
2 min read.Are you getting an error like “The SPListItem being updated was not retrieved with all taxonomy fields” when you try adding or modifying values in a TaxonomyField of a list item in SharePoint, either using the GUI or with PowerShell or even programmatically? Then read ahead, I’ve got a quick and dirty solution!
Reason
After quick googling and some frustration, I figured out the probable reason for the issue; SharePoint went and broke the link between the internal Note-field and the actual TaxonomyField you’re supposed to be using. And this causes SharePoint to return slightly confusing errors.
In my case, my app actually just got a simple JSON response like below:
{"The SPListItem being updated was not retrieved with all taxonomy fields."}
I’d see this error any time I was trying to modify or create any values of a field of type TaxonomyField. I used OfficeDev.PnP’s TaxonomyExtensions to achieve this, but also tried the “normal” CSOM libraries – and the result was always the same. No amount of ctx.Load(item) -calls would help ;)
Like so many times with SharePoint, the solution’s simple, yet frustrating.
Solution
Remove and recreate the field. The field is broken, removing and recreating it will fix it. For me, that was a no-brainer, since all of the values were set programmatically anyway. It was easy to just restore everything by running my code again.
However, in real-life situations, this might not always work. In that case, you can recreate the Notes field and reassociate it to the TaxonomyField. The code I borrowed below is for On-Premises, but the concept should work for SharePoint Online, too:
private void MapManagedMetadataField(Guid fieldId, Guid noteFieldId, SPSite site, string sTermStore, string sTermGroup, string sTermSet) { if (site.RootWeb.Fields.Contains(fieldId)) { TaxonomySession session = new TaxonomySession(site); if (session.TermStores.Count != 0) { var termStore = session.TermStores[sTermStore]; var group = GetByName(termStore.Groups, sTermGroup); var termSet = group.TermSets[sTermSet]; TaxonomyField field = site.RootWeb.Fields[fieldId] as TaxonomyField; // Set Manage Metadata's Text field to Note field field.TextField = noteFieldId; // Connect to MMS field.SspId = termSet.TermStore.Id; field.TermSetId = termSet.Id; field.TargetTemplate = string.Empty; field.AnchorId = Guid.Empty; field.Update(); } } }
See these blog posts for more details.
- Check out step 5 here: https://tjendarta.wordpress.com/2013/07/19/create-managed-metadata-column-taxonomyfieldtype-in-visual-studio/ (I borrowed the code from his post!)
- Useful CSOM methods for managing Managed Metadata programmatically: https://unnieayilliath.com/2015/08/24/sharepoint-2013-updateclear-taxonomy-field-value-using-c-csom/
- TaxonomyExtensions on OfficeDev.PnP: https://github.com/SharePoint/PnP-Sites-Core/blob/master/Core/OfficeDevPnP.Core/Extensions/TaxonomyExtensions.cs
- M365 Copilot claiming “You have turned off web search in the work mode”? Easy fix! - November 19, 2024
- “Performing cleanup” – Excel is stuck with an old, conflicted file and will never recover. - November 12, 2024
- How to add multiple app URIs for your Entra app registration? - November 5, 2024