Hello Friends,
Welcome back with another post on Power Automate. We are going to start another series of Power Automate upon Permissions at item level. In this post, we will discuss about -
- Stop Inheriting Permissions
- Delete Unique Permissions (Restore Inherited Permissions)
Let's take one by one.
- Stop Inheriting Permissions-
- First of all create a list named "TestList". There would a default column supplied "Title".
- Click on App Launcher (9 dots) at top left corner and then click on Power Automate.
- Click on "+ Create" and then choose "Automated cloud flow".
- A popup will appear. Give you flow a suitable name and then select the trigger as "When an item is created (SharePoint)".
- Provide the Site Address and the List Name upon which you need to perform action.
- Then add an action Compose to save the list name as we have to use the list name repeatedly therefore, we will use the output of this compose action. Rename this action as "Compose - ListName".
- Now add one more action "Send an HTTP request to SharePoint". Rename it as "Send an HTTP request to SharePoint - Stop Inheriting Permissions". This action has 5 parts-
- Site Address - Provide Site Address
- Method - Choose POST
- Uri - _api/lists/getByTitle('@{outputs('Compose_-_ListName')}')/items(@{triggerOutputs()?['body/ID']})/breakroleinheritance(copyRoleAssignments=false,clearSubscopes=true)
- The lime highlighted part is ListName. We will use the Outputs of Compose action.
- The aqua highlighted is Item ID. We will use the ID from When an item is created action.
- Headers - Leave Blank
- Body - Leave Blank
- Save the flow and come back to SharePoint list. Add an item.
- Now quickly check the permissions of this item. You will find the item is inheriting parent list permissions.
- Now check the execution status of flow. Once it shows success, then check the permissions again.
- You will find that inheritance of permissions has been stopped. Only you will be having the access on this list item.
- Apart from you, Site Collection Owners also have permissions on this list item. Rest all permissions have been removed.
- This way you can stop inheritance of permissions.
- Now, what if, we have to restore the permissions. Here is the solution.
- Delete Unique Permissions (Restore Inherited Permissions)-
- In section #1, we have seen how to stop inheritance of permissions. Now some times, we need to restore the inheritance. So, here we will see the implementation of the same.
- In above flow, add one more action "Send an HTTP request to SharePoint". Rename it as "Send an HTTP request to SharePoint - Restore Inheriting Permissions". This action has 5 parts-
- Site Address - Provide Site Address
- Method - Choose POST
- Uri - _api/lists/getByTitle('@{outputs('Compose_-_ListName')}')/items(@{triggerOutputs()?['body/ID']})/ResetRoleInheritance
- The lime highlighted part is ListName. We will use the Outputs of Compose action.
- The aqua highlighted is Item ID. We will use the ID from When an item is created action.
- Headers - Leave Blank
- Body - Leave Blank
- Save the flow and click on Test >> Automatically >> With a recently used trigger >> Succeeded.
- The Test feature allows us to use the same list item. As we already stopped the inheritance, therefore, using the same list item will give us the visible result.
- Now, click on the Test button provided at the bottom. It will execute the flow. Wait for a couple of moments to perform the activity by flow. A few moments later you will get the screen like below 😉
- Now go back to the permissions page and refresh the same. You will be surprised to see that unique permissions have been vanished. The item again started inheriting permissions. Wow!
- This way, you can Set/Reset the Permissions Inheritance.
- In case, if you wish to remove only particular group then you need to use below Uri-
- _api/web/lists/getByTitle('[LIST_TITLE]')/items([ItemID])/roleAssignments/groups/removebyid([Group_PRINCIPLE_ID])]
- Key Points-
- Stopping Permissions Inheritance removes all the permissions except-
- Creator of that item
- Site Collection Admins
With this, I am concluding this post.
Happy Coding !!!
Will see you again with some new topics.
Stay Safe !
Stay Healthy !
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.