I am trying to write the value of a managed metadata column across several documents in a document library at once using JSOM, but for some reason the way I'm trying only writes the value to the first item in my set that I write to.
For example, say I have two columns, a text field and a managed metadata field. I can loop over every document and write to both fields. The text field will get written to every document correctly, but the managed metadata value only gets written to the first document for which I call item.update(); The value of the managed metadata field is correct, and it does definitely work properly for the first item at least.
I have tried both of the following patterns for the value:
'Label Text|0f21b3b6-7701-4da1-991a-05355ac64393'
'1033#;Label Text|0f21b3b6-7701-4da1-991a-05355ac64393'
I've pared down a simple test case code sample demonstrating my example above:
var fieldValue = '1033#;Supply Chain|0f21b3b6-7701-4da1-991a-05355ac64393';
var fieldName = 'test_x0020_managed_x0020_metadata';
var listName = 'Documents';
var context = SP.ClientContext.get_current();
var query = new SP.CamlQuery();
query.set_viewXml('<View><Query></Query></View>');
var items = context.get_web().get_lists().getByTitle(listName).getItems(query);
context.load(items);
context.executeQueryAsync(function() {
var enumerator = items.getEnumerator();
while(enumerator.moveNext()) {
var item = enumerator.get_current();
item.set_item('other_fields', 'get_written_to');
item.set_item(fieldName, fieldValue);
item.update();
}
context.executeQueryAsync(
function(sender, args) { console.log(arguments); },
function(sender, args) { console.log(arguments); }
);
}, function(sender, args) { console.log(arguments); });
I've tried to use SP.Taxonomy.TaxonomyFieldValue as well, but I get the same results. Is it just not possible to write managed metadata columns across multiple documents in one executeQueryAsync call?