This is a follow up from my previous post on Creating SharePoint Online Document Set in Microsoft Flow.
We’ve created the document set, and now we want to update some of the properties for the document set, one of which is a single value taxonomy field.
Assuming add-in only authentication has been set up and the access token has been obtained with a HTTP action and parsed into JSON, as per the previous blog post.
We now have actions after creating our document set to update the document set.
Step 1: HTTP – Create Document Set
This is the final step in the previous blog post where we use a HTTP action to call the SharePoint REST API to create a document set in a SharePoint document library.
Step 2: Parse JSON – Document Set
We use the Parse JSON action to convert the body response from the Create Document Set HTTP call into a JSON object. Our goal here is to simply get the ID for the newly created document set.
Step 3: HTTP – Update Document Set
Now we use a HTTP Post to update the document set. Notice that we’re not using the Folder REST API, because we’re updating custom fields that are outside the bounds of SP.Folder fields. We Post to <site_collection_url>/<site_url>/_api/web/lists/getbytitle(‘<list_name>’)/items(<item_id>), using the full site collection and web url to the target list, getting it by its name, and setting <item_id> to the document set item ID we can get from the Parsed JSON object above.
Authorization token is set the Bearer <access_token> based on the token we would have previously obtained. X-HTTP-METHOD is set to MERGE to perform an update, and If-Match is just set to “*” for simplicity, although you can try and get the etag from the parsed JSON above as well.
The Body shows the JSON required to perform update on various field types. First and foremost, we need to set the __metadata type to SP.Data.<list_name>Item, where <list_name> is the name of the list you’re updating to. In this example, the list name was Documents, so we use SP.Data.DocumentsItem. If the list name is “CustomListName”, you will set type to SP.Data.CustomListNameItem.
Setting text and number fields are straightforward, just set the JSON key/values as required.
Lookup fields and multi lookup fields are interesting. We need to set the key value <lookup_field_internal_name>Id. So for the example above, we have a lookup field with internal name “LookupField”, and a multi lookup field with internal name “MultiLookupField”. See how we’re using the JSON key values of “LookupFieldId” and “MultiLookupFieldId” to set the lookup IDs, whether a single or an array of integers.
To set a single value taxonomy field, we set it to a custom JSON object that has 2 keys, TermGuid and WssId. TermGuid is set to the Unique Identifier of the term you want to set to in your term store. WssId always needs to be set to -1. If it does not exist, the taxonomy field update won’t work. There is an optional Label key you can set as well, but it makes no difference as the update will pull the term’s name based on the TermGuid.
One thing to note is that we supposedly can’t update multi value taxonomy fields using the Rest API. Have not experimented on this myself, but may update this in the future if I get around to it.
Update 3/09/2018: So updating multi value taxonomy fields are possible, but quite convoluted. Thanks to https://www.aerieconsulting.com/blog/update-using-rest-to-update-a-multi-value-taxonomy-field-in-sharepoint for outlining how it can be done. Below is a screenshot on how it can be set up in Flow, where lfc34abda35f47c490ba3073880515cb is the StaticName for the Note field created to store data for a multi-value taxonomy field in my example.