The SPListItem being updated was not retrieved with all taxonomy fields

The problem definition is simple , you have some taxonomy fields on a list or in a content type which is using manage metadata columns . When you edit an item and try to save you will facing an error like validation error

The SPListItem being updated was not retrieved with all taxonomy fields”

Ok lets start and give some information , I have recently faced this issue and make a couple research internet to find a solution .
And i found some suggestions but it is dangerous !.

For example :

To fix this go to Central Administration, Manage Web Applications, select the web application, and then choose the dropdown under General Settings select Resource Throttling.

The setting for List View Lookup Threshold and raise it from the default 8. it can go up to 1000 although you are unlikely to need this many lookups.”

!!! Please do not change or exceed SharePoint Boundaries and Limitations (unless Microsoft told do so) . There is a reason that SharePoint Product group relaese these boundaries and limitations .
As you may see many articles suggests increase the “List View Lookup Threshold” , No ! if you do that in a highly utilizated production environment , your sharepoint can be unreachable and face absolute dead-lock stiuations in SQL server .

I could not expose the source code but you can find the details if you know how to use reflector.
This error only happen we have static function TouchAllTaxonomyColumns called when saving a list item which contains Taxonomy Fields.
And  when this function called , we looping all taxonomy fields in that library (added by content type or manually) , not only the one you want to update .Thats mean any of the taxonomy field in that libary have any problem then you will see this error .

For example you have added two taxonomy field to a Pages Library , One of them comming from a content type and it is healty . and the second one was added manually and have a problem .
Then you are creating a Page and editing the page by using this Content Type, you will see only the first taxonomy field because this content type does not contains the second (problematic) taxonomy field . Even so when you try to save you’ll see this error . Because when you save an item we are touching all taxonomy fields present in library at behind .

So what can be the problem of the second taxonomy field ?

1 )This problem mostly happens when you move content types between site collections by powershell or using 3rd party tools or SharePoint Manager.
Every SharePoint Site Collection has a TaxonomyHiddenList . And if you check for the Field definition you will see there is a reference to TaxonomyHiddenList in LookupList property.
So if you move a site column or a content type have a taxonomy field from an another site collection the lookuplist id must be updated ! otherwise it will be pointing a different TaxonomyHiddenlist which is not present in target site collection .
SchemaXML looks like below:
<FieldType=“TaxonomyFieldType” List=“{<TaxonomyHiddenListGUID>}” WebId=“<GUID>“ …..

you can find the correct TaxonomyHiddenList id by running following powershell;
$site = get-spsite http://contoso.com
$web = $site.OpenWeb()
$web.Lists | sort Title | ft id,title

The verify the problem check for all taxonomy fields in the Library ( I used Pages library for a sample)
$list = $web.Lists[“Pages”]
$list.fields | ? { $_.typeasstring -like “Taxo*” } | ft InternalName

then check for every taxonomy field to see what is the LookupList
$field = $list.Fields.GetFieldbyInternalname(“<internalname of the field>”)
$field.LookupList

It will show you the GUID of bounded TaxonomyHiddenList , compare with the TaxonomyHiddenList Guid in that Site Collection . If it is different then you have the problem !.

The resolution is delete the problematic taxonomy fields and re-create it . Well it is not an easy process , you may need to clean from content type or dependent parents that using it .

2) Another issue managed metadata field type required additional Notes field type as well.If you have a missing “Note” field type some how , you will face this problem .
$field = $list.Fields.GetFieldbyInternalname(“<internalname of the field>”)
$field.TextField
Shows you the dependant Note field , if it is not present , then you have a problem of your custom creation or migration code/script.

Advertisements

TaxonomyWebTaggingControl – Sharepoint

Hi guys , in this article i will tell you how to use TaxonomyWebTaggingControl . First of all i assume that you already define your terms and terms sets in your sharepoint managed meta data service.This control help us that show and set this terms for various purpose. Msdn says “A TaxonomyWebTaggingControl object is a Web control that can be added to a page so that a user can pick one or more taxonomy Term object from a specific TermSet object or from an entire TermStore object.”

First we register control in our page definition.

<%@ Register Assembly="Microsoft.SharePoint.Taxonomy, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
    Namespace="Microsoft.SharePoint.Taxonomy" TagPrefix="cc1" %>

And control in the content like this

<cc1:TaxonomyWebTaggingControl ID="TaxonomyControl" runat="server" >
</cc1:TaxonomyWebTaggingControl>

At code behind we getting taxonomy store from metadataservice and set the control properties

Dont forget to add your libraries.

using Microsoft.SharePoint.Taxonomy;
using Microsoft.SharePoint;
And your code here
SPContext context = SPContext.Current;
SPSite site = context.Site;
TaxonomySession session = new TaxonomySession(site);
TermStore termStore = session.TermStores["Managed Metadata Service"]; //if you a custom meta service you should change name.
Group group = termStore.Groups["MyGroup"];
TermSet productsTermSet = group.TermSets["Genders"];

.the code above just getting metadata objects from service via using taxonomy entities.

In my code i am usign UserProfileService which has a user property named “Gender” means “Male,Female” which is defined in metadataservice. I am going to set TaxonomyWebTaggingControl (ID: TaxonomyControl) and get value from this control.

Bind the control with entities

TaxonomyControl.SspId.Add(termStore.Id);

TaxonomyControl.TermSetId.Add(productsTermSet.Id);

TaxonomyControl.IsAddTerms = true;

TaxonomyControl.AllowFillIn = true;

TaxonomyControl.IsMulti = false;

Setting data to control with userprofile object:


string
termName = service.GetUserPropertyByAccountName(loginName, ProfileProperties.Genders).GetSingleValue();// don’t worry about this line this is not in our concept.Just know this line getting value from UserProfileService as string.

TaxonomyControl.Text = string.Format(“{0}|{1}”, termName, productsTermSet.Terms[termName].Id.ToString());

TaxonomyWebTaggingControl has a propery named “Text” . You should set this property  “[Label] | [Guid]” format.
Set values into this control as pairs of labels and GUIDs. The delimiter between a label and a GUID is the | character. When using multiple values, delimit them with a ; character. Example: term1|12345678-1234-1234-1234-123456789012;term2|87654321-4321-4321-4321-210987654321

Getting data from control :

TaxonomyFieldValueCollection portfolioCountriesValues = new TaxonomyFieldValueCollection(String.Empty);

portfolioCountriesValues.PopulateFromLabelGuidPairs(TaxonomyControl.Text);

profile[ProfileProperties.Genders].Value=  portfolioCountriesValues[0].Label;

We are using TaxonomyFieldValueCollection class that help us parsing data.

For More info:

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.taxonomy.taxonomywebtaggingcontrol.aspx

Happy codding…