Recently we did a couple of Project Server/Online Implementation based projects which included customizations like Demand Management Workflow, Document Approval workflow, Issue or Risk Escalation workflow and much more. This required Project workspace customization to enable standard processes for every project within client EPM tenant setup. During these customizations, one challenge was to apply an item approval workflow for a custom list of the workspace, and when the list item is approved, the list item should be copied/moved to another list which has all approved list items only.
We thought this should be an easy solution using SharePoint designer workflow and should not take much time to implement 🙂 but twist came when we found that a list item can be copied easily by using Create new list item/Update List item workflow activity but any managed metadata column does not follow this.
Below is the detailed error and solution, how we customized the managed metadata updates on a SharePoint list using SharePoint Designer.
Scenario:
In SharePoint Designer you can use the “Update List Item” action to update a field in list or document library. But, whenever you update a managed metadata field through the “Update List Item” action, or you create an item from one to another list containing managed metadata field through the “Create item” action, a BadRequest error occurs:
Follow below-given steps for the solution to your problem:
Let’s, create two SharePoint lists, Pending Links & Approved Links. New link item is added to Pending Links; then it is routed to Link Managers for approval. If link item is approved then it is copied to Approved Links, else remains in Pending Links. Add managed metadata field, for, e.g., LinkKeywords, to both lists.
Both Pending Links and Approved links contains these 3 fields :
Note: Managed metadata field name should not contain a blank space. Otherwise managed metadata field value would not be updated using workflow.
SharePoint will automatically add another field called “LinkKeywords _0”.
Steps
1. Get the internal name of LinkKeywords_0:
Go to https://xyz.sharepoint.com/site/_api/web/lists/getbytitle(‘listtitle’)/fields
Static name for LinkKeywords_0 hidden field is “f718726da5da46c797e9ad5bc6911db9”.
2. Get the list item type entity type full name:
Go to https://xyz.sharepoint.com/site/_api/web/lists/getbytitle(‘listtitle’)
ListItemEntityTypeFullName of Approved Links is “SP.Data.
Standard format for ListItemEntityTypeFullName is “SP.Data.<>ListItem”. Space in list title will be replaced by “_x0020_”.
3. Add workflow action to create item:
Use workflow action “Create list item”.
Item will be created from Pending Links to Approved Links, whenever task outcome is approved. Add fields other than managed metadata field. The outcome of this process will be taken into NewItem variable of GUID type.
Here, do not add managed metadata type field otherwise you will get error “An unexpected ‘PrimitiveValue’ node was found when reading from the JSON reader. A ‘StartObject’ node was expected”.
Now, workflow has been configured to create item in Approved links, but managed metadata field has not been updated on list item. To do this you need to use workflow action “Call HTTP Web Service” followed by building required dictionaries.
4. Build Headers dictionary to store following headers:
Use workflow action “Build Dictionary”.
5. Build metadata dictionary for List item type:
Use workflow action “Build Dictionary”.
6. Build the data dictionary:
Use workflow action “Build Dictionary”.
7. Call HTTP Web Service:
Use workflow action “Call HTTP Web Service”.
Add Service URL of item to be updated:
ID can be retrieved as:
Where NewItem is GUID of item added to Approved Links, on which you want to update managed metadata field value.
Change HTTP method to HTTP POST:
Set HTTP Web Service Properties as:
8. Publish workflow. Final workflow appears as:
9. Add new item to Pending Links as:
10. When a new item is created, it’s approval status will set to Pending Approval as:
A task approval will be processed for Link Managers.
11. If link item is approved then Approval Status will set to Approved:
12. New item will be added to Approved Links as:
So, now using these steps you can updated managed metadata field. Hope, it was helpful to you.