Updating Approval Details in SharePoint Library using 'Send HTTP Request to SharePoint' in Power Automate
Updating Approval Details in SharePoint Library using ‘Send HTTP Request to SharePoint’ in Power Automate
In Power Automate, there are two methods for updating file properties:
- Send HTTP Request to SharePoint
- Update File Properties
While the latter suffices for most cases, I opted for the “Send HTTP Request to SharePoint” in specific scenarios:
- To avoid triggering a new file version using system update.
- When modifying system columns such as author or modified date.
- When updating an image column.
- To update fields without having to fill in required fields.
Upon approval of a document, I needed to update file properties with the approval outcome, comments, date, and approver without generating a new version. This necessitated the use of the “Send HTTP Request to SharePoint” action.
After several iterations overcoming some challenges, the fields were successfully updated:
In my scenario, I employed the “First to Respond” approval type:
After the approval is completed, the approval details are saved back to the SharePoint library.
Capturing Details from Completed Approval Steps
Approver
Initially, I used the syntax
i:0#.f|membership|outputs('Get_user_profile_(V2)')?['body/mail'].
The flow succeeded and the step did not throw any exceptions despite the approver field was not updated.
I found the accurate syntax for updating a person field by examining the network trace in the developer tools of the browser by simulating the update of a person field in SharePoint and capture the corresponding API call. The claims of the user need to be passed with a key property to update the person field.
[{'Key': 'i:0#.f|membership|@{outputs('Get_user_profile_(V2)')?['body/mail']}'}]
Date
The date needs to be tweaked for the correct datetime string, otherwise you might encounter the following error message.
“You must specify a valid date within the range of 01/01/1900 and 31/12/8900.”
I used the following datetime format ‘dd/MM/yyyy HH:mm’.
formatDateTime(outputs('Start_and_wait_for_an_approval')?['body/completionDate'],'dd/MM/yyyy HH:mm')
However, there were issues with the date format. For instance, if the date column type is “date only,” providing ‘dd/MM/yyyy HH:mm’ as the format will result in the following error:
After updating the column to include time, using the date format still produced an exception. This was due to the regional settings for the site being set to En-US instead of En-UK. After rectifying this in the site settings under “Regional Settings” (/_layouts/15/regionalsetng.aspx), the issue was resolved:
Comments
I initially accessed the comments using the expression:
outputs('Start_and_wait_for_an_approval')?['body/responses'][0]['comments']
However if no comments are provided during approval, the flow fails.
To prevent the error I used the ‘?’. This is particularly useful for navigating through potentially nested structures where some properties may or may not exist. For instance, if outputs(‘Start_and_wait_for_an_approval’) returns an object, and it has a property body which is also an object, and within that, there’s a property responses which is an array, the ?[0] ensures that you’re trying to access the first element of that array only if it exists.
outputs('Start_and_wait_for_an_approval')?['body/responses']?[0]?['comments']
References
Working with the SharePoint Send HTTP Request flow action in Power Automate
SP.ListItem.validateUpdateListItem Method
Parsing JSON in Power Apps by the amazing Cat Schneider