Monday, June 01, 2015

Taxonomy field value doesnt set

We had a puzzle today, which we were sure was an issue with the document property parser in SharePoint. Every time we tried to set the value of a specific column using either our existing powershell script or an event handler that works on every other library in the system, the document would be updated with the property value, but after a second we'd refresh the page and see the value went back to null.


It was frustrating! I was sure it was because the document had an empty value in the document properties that was overriding the value from my code - despite the fact that my code is implemented with a delay to ensure it runs after the parser.


We troubleshooted several ways and couldn't find the solution...until we noticed something weird when we were looking at the content type schema - the taxonomy field was set to support multiple values! our code was specifically written for that field, which is not supposed to support multiple values. Some nasty little elf went into the column setting in the library and changed my precious from its normal settings. Setting it back and everything went to normal.

Moral of the story - since setting a taxonomy field's value in code is different if the field supports multivalue or not, make sure either your code is robust enough to handle a nasty user making a change, or tell your users to keep their hands to themselves!

No comments: