Showing posts with label Power Portal. Show all posts
Showing posts with label Power Portal. Show all posts

December 21, 2020

How to Manage Item Level Permission with different Role Definitions using Power Automate?

Introduction:

In this blog, we will learn how to set item level permission on SharePoint List/Library using Power Automate with different role definitions. 

Scenarios:

We have come across with a requirement wherein we need to apply item level permission to a specific SharePoint group with different role definitions. In OOTB Workflow, this is very simple and easy. With Power Automate how we can manage this? We will discuss this in this article.
Below are the steps we are going to automate here!

1. Break the current Item Permission
2. Get ID for our SharePoint Group
3. Assign Role definition for a specific item to our SharePoint Group 

Step 1: Break Current Item Permission

1. Add a new "Send an HTTP Request to SharePoint" action.

2. To add/replace the permission on an item level, we first need to Break the Permission Inheritance.

Site Address: Select the site in which the List/Library resides.
Method: POST
Uri:/_api/web/lists/getByTitle('[List/LibraryName]')/items[ItemID])/breakroleinheritance(copyRoleAssignments=false, clearSubscopes=true)

Here, parameter copyRoleAssignments = true/false. This specifies if we want to copy inherited permission or not. If set to true, then it will copy the inherited permission else it will remove all the users when breaking the inheritance.

Step 2: Get ID for our SharePoint Group

1. Add a new "Send an HTTP Request to SharePoint" action.
Site Address: Select the Site in which the group resides
Method: GET
Uri: /_api/Web/SiteGroups/GetByName('[Group Name]')?$select=Id

2. Parse JSON.

Add below JSON payload in “Schema” section.
 {  
   "type": "object",  
   "properties": {  
     "d": {  
       "type": "object",  
       "properties": {  
         "__metadata": {  
           "type": "object",  
           "properties": {  
             "id": {  
               "type": "string"  
             },  
             "uri": {  
               "type": "string"  
             },  
             "type": {  
               "type": "string"  
             }  
           }  
         },  
         "Id": {  
           "type": "integer"  
         }  
       }  
     }  
   }  
 }  

Step 3: Assign Role definition for a specific item to our SharePoint Group 

1. Add "Send an HTTP Request to SharePoint" for assigning the permission to the group/user we fetched in above step.


Site Address: Select the site in which the List/Library resides.
Method: POST
Uri: /_api/web/lists/getByTitle(‘SiteName’)/items([Item ID])/roleassignments/addroleassignment(principalid=[Id from Prase JSON step], roledefid=1073741829) 
 
Here, Roledefid = id for specific role. Roledefid for following roles are as below:
⦁ Full Control = 1073741829
⦁ Edit = 1073741830
⦁ Read = 1073741826

 For specific tenant if we want to find role definition id then use below URL:

API: "[Site URL]/_api/web/roledefinitions?$select=Name,Id" 

This will give you roledefid for following access rights:

⦁ Design
⦁ Contribute
⦁ Limited Access
⦁ Limited View
⦁ Limited Edit
⦁ View Only
Set the appropriate roledefid for the provided access roles.

 

Conclusion:

This is how we can assign specific role definition to a specific group to maintain item level permission using Power Automate. 

If you have any questions you can reach out our SharePoint Consulting team here.

March 26, 2020

How to change Date and Time Format in Microsoft Flow or Power Automate?

Introduction:
In this blog, we will learn, how we can change the date and time format in Microsoft Power Automate. Sometimes, there are situations in which we need to change the format of the date and time value.

Let’s say for an example if our date time value is 2020-01-30T07:51:09Z and we wish to convert this value to “01/30/2020 07:51:06 AM” format, then we need to use some expression in MS Flow or Power Automate.

Real-Life Use Case:
In this article, we will format the date and time value to “MM/dd/yyyy hh:mm:ss AM/PM” format for SharePoint list item. We already have a SharePoint list with OOTB “Created” column. We will change the format of Date and Time in Power Automate. So, now let’s get started!

Step 1:
We have the following list structure. and would need to convert "Created" column to “MM/dd/yyyy hh:mm:ss AM/PM” format, and store this converted value in a variable.

Step 2:
Add a Trigger: When an item is created to the SharePoint list. Add Site Address and List Name.

Step 3:
Initialize variable, to store the value of the converted date and time. Add an action: Initialize variable.

Step 4:
Now, let’s set the variable and change the date and time format using below formula:

formatDateTime(triggerBody()?['Created'],'MM/dd/yyyy hh:mm:ss tt')

Here, we need to pass, the date time value as a first parameter and in the second parameter, we need to pass the format for the specific date and time value. 

Save the flow. We can check the formatted date and time value from this variable.
In the end, MS flow will look like in the following screenshot.

Now, let’s run the flow and check the result.

Test:
Let’s create one item in the SharePoint list to trigger a flow.

Here, our date and time format for the “Created” date is changed and stored in the variable successfully.

Conclusion:
This is how, we can easily change the format for the date and time column in Microsoft Power Automate. Isn’t it amazing?

If you have any questions you can reach out our SharePoint Consulting team here.