Using Microsoft Flow and SharePoint Api for checking Document Read privileges based on Team in Microsoft Dynamics 365.

 Hello Guys,

In our previous blog we have seen how you can check which users are having SharePoint Document read permission once you share Record with another CRM user. Today we will see the same concept but not with user, instead with team.



Before we start, if you are new to our blog then do follow us to know more about Dynamics and Power Platform. Also if you like our blog then please comment and share this blog with your friends.

Also before start i will recommend to read my previous blog.

First of all we will be creating one named "Docs Team" and will add some crm users in that team as shown below.




Now we will be login with one crm user named "Malishka Gupta" and will create one new contact and will upload one document for that contact.




As you can see in above picture, we have created a contact named "Vihan Ranjan" and uploaded a document for the same. Malishka Gupta can see this document in SharePoint site as well.




Now we will be changing the Owner of the record from "Malishka Gupta" to team "Docs Team".




As you can see we have assigned this contact to team. Now will be creating a flow which will send HTTP request to SharePoint site and will check which users are having permission to read this documents.

Navigate to https://us.flow.microsoft.com and select your environment. Click on New and select Instant -from blank. Configure it as below.



Click on Create button.Now on the next screen click on First step i.e. Manually trigger flow and click on its Add an Input and select Text and configure it as below.




Click on Add new step and search Initialize variable. Configure it as below.



Click on Add new step and search Send an HTTP request to SharePoint. Configure this step as below.



Click on Add new step and search Parse Json and configure it as below.



In Schema Paste below Json Schema.

{
    "type""object",
    "properties": {
        "d": {
            "type""object",
            "properties": {
                "__metadata": {
                    "type""object",
                    "properties": {
                        "id": {
                            "type""string"
                        },
                        "uri": {
                            "type""string"
                        },
                        "type": {
                            "type""string"
                        }
                    }
                },
                "ListItemAllFields": {
                    "type""object",
                    "properties": {
                        "__metadata": {
                            "type""object",
                            "properties": {
                                "id": {
                                    "type""string"
                                },
                                "uri": {
                                    "type""string"
                                },
                                "etag": {
                                    "type""string"
                                },
                                "type": {
                                    "type""string"
                                }
                            }
                        },
                        "RoleAssignments": {
                            "type""object",
                            "properties": {
                                "results": {
                                    "type""array",
                                    "items": {
                                        "type""object",
                                        "properties": {
                                            "__metadata": {
                                                "type""object",
                                                "properties": {
                                                    "id": {
                                                        "type""string"
                                                    },
                                                    "uri": {
                                                        "type""string"
                                                    },
                                                    "type": {
                                                        "type""string"
                                                    }
                                                }
                                            },
                                            "Member": {
                                                "type""object",
                                                "properties": {
                                                    "__metadata": {
                                                        "type""object",
                                                        "properties": {
                                                            "id": {
                                                                "type""string"
                                                            },
                                                            "uri": {
                                                                "type""string"
                                                            },
                                                            "type": {
                                                                "type""string"
                                                            }
                                                        }
                                                    },
                                                    "Users": {
                                                        "type""object",
                                                        "properties": {
                                                            "results": {
                                                                "type""array",
                                                                "items": {
                                                                    "type""object",
                                                                    "properties": {
                                                                        "__metadata": {
                                                                            "type""object",
                                                                            "properties": {
                                                                                "id": {
                                                                                    "type""string"
                                                                                },
                                                                                "uri": {
                                                                                    "type""string"
                                                                                },
                                                                                "type": {
                                                                                    "type""string"
                                                                                }
                                                                            }
                                                                        },
                                                                        "UserPrincipalName": {
                                                                            "type""string"
                                                                        }
                                                                    },
                                                                    "required": [
                                                                        "__metadata",
                                                                        "UserPrincipalName"
                                                                    ]
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        },
                                        "required": [
                                            "__metadata",
                                            "Member"
                                        ]
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

Click on Add new step and search Apply to Each and configure it as below.



Inside the Apply loop click on Add and Action and Add condition and configure it as below.



In Yes block click on add an action. Search Apply to each and inside the Apply add and action Append to An Array and configure it as below.



Now add a new step outside to apply and search initialize variable and configure it as below.



Add a new step and search compose and configure it as below.



union(variables('User Array'),variables('User Array'))

Add a new step and set variable as below.



So our flow is ready and now we will test it.Click on Test at Top at the left corner. Provide folder name of the record where document is stored and click on Run flow.



As you can see the outputs, these users are having read access to SharePoint Document for contact Vihan Ranjan_9FB2836D04F8EA11A815000D3A5306E5 as we have changed the owner of this record to team. These members are available in that team.



Hope it helps...

Comments

Popular posts from this blog

Read Only Sub Grid & Editable Sub grid in Dynamics 365

Understanding Sales Process in D365.

Understanding Business Unit in Dynamics 365.