-
-
Notifications
You must be signed in to change notification settings - Fork 58
Add or Update a Term aka Taxonomy aka Managed Metadata
SharepointPlus uses Web Services for many tasks. One of them is for adding/updating the properties/fields/columns of an item/file.
Sharepoint needs special format based on the column's type for the add/update operations. I've already documented these formats into the SharepointPlus documentation.
However the Term / Taxonomy / Managed Metadata type needs more explanations than a short sentence. Based on this blog post I've been able to understand how it works and to explain it.
Use the Term Store to create your terms, then add a Managed Metadata column into your list. For this example I'll use Tags for the field's name.
You first need to retrieve the info for your list, especially the StaticName:
$SP().list("The_List").info(function(fields) {
for (var i=0; i<fields.length; i++) console.log(fields[i]["DisplayName"]+ " => "+fields[i]["StaticName"]+": "+fields[i]["Type"]);
});
It will return all the columns for your list. You'll notice your Managed Metadata column. In my example:
Tags => Tags: TaxonomyFieldTypeMulti
But you'll also find another column with a name that starts with your Managed Metadata column's name, and with the type Note. In my example:
Tags_0 => i475c910878e4a92841e50c0a2f74238: Note
Here the internal name for this second hidden field is i475c910878e4a92841e50c0a2f74238.
So we need to update this special field using the below format:
0;#|Unique_Identifier
You can manually and easily find it into the Term Store Magement from your site settings. Navigate to your term and you'll find this identifier at the bottom of the term's properties, under Unique Identifier.
If your field is a multiple selection (just like into my example), you have to use ;# to separate the different terms:
0;#|FirstTermUniqueIdentifier;#0;#|SecondTermUniqueIdentifier
You can now add or update your list:
$SP().list("TheList").update({
ID:"11",
i475c910878e4a92841e50c0a2f74238:"0;#|43bf6b09-e2c4-4dbe-90fc-8ac8c64421f2"
});