Problem Statement
Update SharePoint list item accepting multi-value over Managed Metadata Field using Logic App.
Pre- Requisite
- Azure Logic App ( with appropriate permission on SharePoint env).
- Sharepoint List with field Type Taxonomy Field accepts multiple values.
Background Info
- Using the Sharepoint rest api endpoint, one can perform CRUD operations on SharePoint list Items.
- SharePoint expects the standard payload body structure, headers information, and appropriate endpoint mapping to serve a request.
- Different MethodTypes are used to perform various operations on SharePoint List/library using rest endpoints.
- To Update List Item - it is recommended to use the below headers info with MethodType as "POST".
{
"If-Match": "*",
"X-HTTP-Method": "MERGE",
"accept": "application/json;odata=minimalmetadata",
"content-type": "application/json;odata=minimalmetadata"
}
- In general, to update a list item in SharePoint list, the endpoint to be consumed is <Tenant url>/sites/<site Name>/_api/web/Lists/getbytitle('<List Name>')/items(<Item Id>).
- Passing Body as below.
{
"<Field 1 InternalName>": <actual Value>,
"<Field 2 InternalName>": <actual Value>,
"<Field 3 InternalName>": <actual Value>
}
- Whereas to Update multi-value fields, the Body has variations as below:
{
"User type column InternalName": {
"results": [userId1, userId2] // userIds as integers
},
"Multi Select column InternalName": {
"results": ["value1", "value2"] // values as strings
}
}
- Attaching a supporting snapshot for an HTTP action in the Azure Logic app to Update items to the list.
Actual requirements
- Let's consider the client has a Sharepoint list Named "Audit List" "consists of TaxonomyField as DisplayName: "Market", FieldType: "Taxonomy Metadata", Type: "accepts multi-value".
- And a library SitePages that allow user to create/Edit.Publish pages with Page properties as DistributionZone. This DistributionZone is also a Taxonomy field accepting multiple values.
- It is expected that When a user creates/Updates an item in the Site pages library, an entry will be created in the Audit List with page property details.
Approach
Part 1. The approach to grab the Change Events from the SitePages library is a separate solution. <WILL BE PUBLISHED SOON>
Part 2. Let's assume that by now, Page has the metadata information (taxonomy field details), and we have the Page ID on which the event happened.
The primary focus is to create/Update an entry to the Audit List by passing correct payload formations.
To operate with a taxonomy field in a list using the rest api endpoint, it requires an extra set of information related to its hidden field associated with each of the taxonomy fields of the list.
SharePoint internally maintains a "Note" typed hidden field against each of the Taxonomy Metadata Fields to persist the actual value of the corresponding list column (Taxanomy type) with postFix as "_0" along with the column title.
Try -this endpoint: <Tenant url>/sites/<site Name>/_api/web/Lists/getbytitle('<List Name>')/fields
to collect the hidden column title.
E.g. as per the above usecase for column "Market" sharepoint will have a hidden field with a display Name as "Market_0" and also have a unique iternalName associated with it.
<d:SchemaXml>
<Field
Type="Note"
DisplayName="Market_0"
StaticName="ka25*******4a8a"
Name="ka25*******4a8a"
ID="{863****-****-****-****-****afd5d}"
ShowInViewForms="FALSE"
InternalName="ka25*******4a8a"
Required="FALSE"
Hidden="TRUE"
CanToggleHidden="TRUE"
ColName="ntext2"
RowOrdinal="0"
SourceID="{dcb9****-****-****-****-****3763}"
/>
</d:SchemaXml>
Hence, it is required to fetch the internal Name of the hidden field of the corresponding Taxonomy field from the list. Using the rest of the endpoints in the fields of the list below, it can be obtained.
endpoint url: <Tenant url>/sites/<site Name>/_api/web/Lists/getbytitle('<List Name>')/fields?$filter=Title eq 'Market_0'&$select=Title,InternalName
- method: GET
- returns: InternalName="ka25*******4a8a".
This initial name is to be referenced in the HTTP call to operate actually for the Taxonomy Field of the list. Any update on this internalNamed column will actually reflect the taxonomy Field of the list.
Implementation
Step 1. Create an Azure Logic app with Manged Identity enabled to grant its accessibility to Sharepoint sites.
Step 2. Configure the Logic app with a trigger. Eg manually (passing item id), and add an HTTP action.
Step 3. Configure the HTTP action method GET to fetch the matching item details from the site pages library //(Source)
Endpoint. <Tenant url>/sites/<site Name>/_api/web/Lists/getbytitle('<SitePages>')/Items(<ItemID>)?$Select=ID,Title,DistributionZone
Step 4. Collect all values from DistributionZone Field // from the above action response to a variable in the logic app.
Step 5. Transform the DistrubutionZone values as a single string with syntax as "WssId;#Term Label|Term GUID".
Use for each condition over DistrubutionZone values and using parse JSON action append all term set value with delimiter as ";"
we will utilize WssId as -1 because SharePoint automatically resolves the correct wssID with a matching Term label. Or create if not found.
Step 6. Configure the HTTP action to fetch the internal name of the corresponding Hidden column for the taxonomy field of the Audit List. // (Destination)
Endpoint. <Tenant url>/sites/<site Name>/_api/web/Lists/getbytitle('<List Name>')/fields?$filter=Title eq 'Market_0'&$select=Title,InternalName
Step 7. Configure the HTTP action to add the item to the SharePoint list with the method type as post. This action will utilize the internal name of the hidden field to reference the taxonomy field of the audit list.
Results