As I stated in my previous post I wanted to demonstrate how to do something in SPD Workflows as well as with Microsoft Flow. In this second part, I am going to be setting SharePoint list-item level security with Microsoft Flow. The steps are very similar, but I still wanted to provide examples for anyone just working away at some of these types of requirements within their own environments.
Preparing Flow Variables
Like an SPD workflow, you can utilize variables within a flow for values later on in the flow. This isn’t something that is done so you need to add the steps. Some of the common values I like to set at the beginning of a flow is the URL of the site I am working with, the header values (not the id’s) and the list name(s).
Get the SP Group ID
Next you want to get the group ID from the SharePoint site. This is done with a SharePoint: “Send an HTTP request to SharePoint” action. You utilize the values set before in the Site Address and the Headers section of the action:
After this step, you need to add a step that gathers the return value from the REST call. To do this you add an Initialize Variable action to the flow and grab the return from the previous step. Note: for the this action you have to use a customized expression: body(‘Get_Test_SP_Group_ID’)[‘d’][‘id’]. Note: the name in the body has to match the name of the action that sends the HTTP call ensuring that any spaces in the name correspond to underscores in the expression.
Setting List-Item Level Security With Microsoft Flow
The step to remove the access is pretty straightforward. The control of the change is actually accomplished in the header of the REST call as opposed to a special endpoint. The endpoint you want to use is as follows: _api/lists/getbytitle(‘<LIST TITLE NAME>/Items(ID)/roleassignments(SP GROUP ID). The special header you want is: X-HTTP-Method: Delete.
Adding a group or account to a list item is a bit more involved. I’ll handle that soon in a future post.
Thanks for reading!!