Introduction

For the last couple of years, Microsoft was promoting MS flow with various supportive features. Now, flow has been re-branded as Power Automate. It has a lot of connectors and actions which help the power users as well as developers to create the approval process, scheduler and business automate process, etc. Recently, Microsoft has declared the deprecation of SharePoint 2010 workflows in SharePoint online, they are suggesting Power Automate (MS Flow) as the alternative. Microsoft also suggesting their online clients migrate their SP 2010 workflows in MS Flow.

In SP 2010 workflow, there was a feature called impersonation step with which we could change the permission of a list item or files. So, with the deprecation of the SP 2010 workflow, this feature will not be available for us. And in SP 2013 workflow, there is no provided action to change permission. So, without custom code, MS flow is the best approach.

In this article, we will explain how to remove and set custom permission for a list item or a library file. The step by step procedure is given below.

Creating MS Flow

Remove all Permissions

Stop sharing an item

Fig 4. Action - Stop sharing an item or a file

Note. This provided action will break the item's inheritance permission. But this action has a catch as if any group or user has “full control” permission in the list, will remain for the item. This action can’t remove their permission from the item.

Set Permissions for User

Set permission

Fig 5. Action – Grant access to an item or a folder

Set permissions for SharePoint Group

With this provided action “Grant access to an item or a folder” in MS flow, we can’t change the permissions of the SP group. Because this action could only recognize the user/group who have an AD email address. As the SP group doesn’t have any, we can change permission for the SP group with this action. To change permission for the SharePoint group, we have to call the REST API endpoint for role assignment. We will use the following rest api to change the permission of the SP group.

_api/web/lists/getbytitle('<List Name>')/items(<List Item ID>)/roleassignments/addroleassignment(principalid='<Group/User’s Principle ID>',roleDefId=<Role Definition ID>)

From the above rest api, we have to change the red marked portion with the respective value. The details are given below.

Send an Http request

Fig 6. Action – Send an HTTP request to SharePoint

Get the Group's Principle ID

People and groups

Fig 7. Getting the group's Principle ID

Run the flow

Conclusion

As we already saw, in this approach with the provided actions we can’t grant permission for the SharePoint group. We need rest api end to point to perform that. Similarly to remove a specific user/group’s permission from an item is not achievable with these provided actions till now MS flow is providing. So, in that situation, we have to use rest API endpoints to manage the item level permission in MS flow.

I hope this article will help you. Be safe. Happy Coding.