Second Life of a Hungarian SharePoint Geek

March 3, 2010

Taxonomy issues

Filed under: Bugs, SP 2010, Taxonomies — Tags: , , — Peter Holpar @ 03:07

During the work with the taxonomy / managed metadata in the past few weeks I found few things that seem at least not a fortunate design decision but some of these are definitely bugs.

Issues with the pipe

When you edit a list item that has a managed metadata field  and you type a single pipe character (“|”) in the text box for the managed metadata field and try to save your item, you get the following exception:

[SPException: Failed to get value of the "YourMetadataColumnName" column from the "Managed Metadata" field type control.  See details in log. Exception message: Value cannot be null.
Parameter name: termId.]
   Microsoft.SharePoint.WebControls.BaseFieldControl.OnLoad(EventArgs e) +21499625
   Microsoft.SharePoint.Taxonomy.TaxonomyFieldControl.OnLoad(EventArgs e) +25
   System.Web.UI.Control.LoadRecursive() +66
   System.Web.UI.Control.LoadRecursive() +191
   System.Web.UI.Control.LoadRecursive() +191
   System.Web.UI.Control.LoadRecursive() +191
   System.Web.UI.Control.LoadRecursive() +191
   System.Web.UI.Control.LoadRecursive() +191
   System.Web.UI.Control.LoadRecursive() +191
   System.Web.UI.Control.LoadRecursive() +191
   System.Web.UI.Control.LoadRecursive() +191
   System.Web.UI.Control.LoadRecursive() +191
   System.Web.UI.Control.LoadRecursive() +191
   System.Web.UI.Control.LoadRecursive() +191
   System.Web.UI.Control.LoadRecursive() +191
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428

——————————————————————————–
Version Information: Microsoft .NET Framework Version:2.0.50727.4927; ASP.NET Version:2.0.50727.4927

When you type a text that contains pipe character (“|”) in the text box for the managed metadata field and try to save your item, the text box is cleared (in contrast to the standard underline and red font color) and you get the following standard validation message:

Creating a new value is not allowed in this field, please select from the existing terms.

Fill-in or not fill-in that is the question

When you have a managed metadata field you can allow fill-in choices as shown below.

image

 

image

image

To enable creating new taxonomy values from the text box, you should set the CreateValuesInEditForm property for your field to true.

  1. SPList list = web.Lists["YourList"];
  2.  
  3. //// to allow tagging on edit form
  4. TaxonomyField taxonomyField = (TaxonomyField)list.Fields["YourField"];
  5. taxonomyField.Open = true;
  6. taxonomyField.CreateValuesInEditForm = true;
  7. taxonomyField.Update();

Setting the CreateValuesInEditForm property is required due to the code in the CreateChildControls method of the TaxonomyFieldControl:

this.webTaggingUI.IsAddTerms = field.Open && (field.IsKeyword || field.CreateValuesInEditForm);

In my code above I set the Open property to true as well, since I had issues when the Open property was not reflected changes made through code in the term set Open / Closed settings.

BTW, do you know why it takes so much time to save term set properties, like Open / Closed changes when working with the Term Store Management Tool UI comparing doing the same from my custom code? Please, let me know! Probably that is because the UI makes some additional work as well, like updating properties of managed metadata fields referring to the term set (see my former issue with the Open property), but I had no time to investigate that in depth.

And there is the anchor

But wait a minute! Setting the CreateValuesInEditForm property does not help in all cases. For example, assume you don’t set the the managed metadata field to be bound to the root of the term set but to a subterm in the term set hierarchy. In code it means that the AnchorId property of your TaxonomyField instance is not Guid("{00000000-0000-0000-0000-000000000000}").

image

In this case when you would like to add a new value by typing it in the text box for the managed metadata field and saving your item. Your value will be underlined and red in the text box but without any validation error. When you check the term set, you find the value was created in the root of the term set instead of the specified subterm level, so it is really not an option for selection.

It is due to the followings. When saving the values, the Validate method of the TaxonomyWebTaggingControl is called that calls the ResolveBoundTerm method that calls the AddNewTerm method. The AddNewTerm method creates the new term through the CreateTerm method, but it does not handle the AnchorId property.

Current code:

term = termSet.CreateTerm(label, termSet.TermStore.WorkingLanguage);

Should be modified by MS:

TermSetItem termParent = (this.AnchorId == new Guid("{00000000-0000-0000-0000-000000000000}")) ? termSet : termSet.GetTerm(this.AnchorId);

term = termParent.CreateTerm(label, termSet.TermStore.WorkingLanguage);

The long, long wait

When you type a text in the text box for the managed metadata field and try to save your item, receiving the "Creating a new value is not allowed in this field, please select from the existing terms." validation message, you can try to resolve the issue by selecting from an existing values as suggested. But when you click on the “Browse for a valid choice” icon right to the text box, the picker is displayed, but the status remains loading and the terms are not displayed.

image

Accepting suggested values

If your managed metadata field allows multiple values, and you type the first value, the control suggests you possible terms. You can accept the suggestions by pressing the Tab key. If you type further after this, the suggested terms appear for the second value, but pressing the Tab has no effect in this case. This issue is a minor one, although can be rather annoying sometimes when working only with the keyboard.

Advertisements

1 Comment »

  1. Note that the “all-zeroes” Guid already has a constant in the libraries, Guid.Empty

    Comment by Tor I. — March 4, 2013 @ 13:53


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: