In this article, you will learn how to add or get the values from metadata column of SharePoint list item. The metadata values can be retrieved and inserted from SharePoint Metadata and stored into metadata column of a list. Each tag has a label with unique id called GUID.
Note: You have to enable the enterprise metadata and keywords settings before proceeding with this example.
Load the required script files with the following snippet.
Get Taxonomy column values:
Here, you will see how to get the tag or metadata column values present already in a SharePoint list item.
Access the list and execute the query
Access the result items set and get the results.
The metadata values can be inserted into SharePoint list items with existing tags or by creating new tag. The tag present in site metadata store can be retrieved and inserted into list item column.
Get tags from Metadata store:
The following steps will help you in getting the tags present already in managed metadata store.
- Get access to taxonomy session object and using getTaxonomySession method, get the session object.
- Get the term store data using the session object and getDefaultSiteCollectionTermStore method. Get the term sets with getTermSetsByName method and termset name. Then, get all terms present in the term store.
- Execute the query and get the terms
- You can see the available tags in two arrays.
Set Tags in to Metadata column of SharePoint list:
The following steps will help you in setting the tag values in the metadata column of a list item.
- After getting the list item, get the taxonomy field to set the term set values. The field must be cast to taxonomy.
- Load and execute the query to get the list item and the available tags.
- Check and add the existing tag values with their id’s into new variable.
- Add the new tag value along with tag id to the tag value above.Note: The new tag value can be inserted by generating new term id. In this example, I am adding a tag which we have retrieved from the metadata store. Refer above section to get the value from metadata store.
- Set the tag values and execute the query