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

 Hello Guys,

In our previous blog we have seen how to implement CB Replicator and why to use CB Replicator.Today we are going to learn how you can check which users are having SharePoint Document read permission once you share Record with another CRM user.



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.



As you can see in above image, we have one contact record named "Shinchan Gupta" which was created by "Malishka Gupta" CRM user. Also this record is shared with read permission by "Malishka Gupta" to "Riya Gupta"(another CRM user).

We will be creating a flow which will return users who are having permission to read Documents attached to this record.

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



Specify Flow details 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"
                        }
                    }
                },
                "Files": {
                    "type""object",
                    "properties": {
                        "__deferred": {
                            "type""object",
                            "properties": {
                                "uri": {
                                    "type""string"
                                }
                            }
                        }
                    }
                },
                "ListItemAllFields": {
                    "type""object",
                    "properties": {
                        "__metadata": {
                            "type""object",
                            "properties": {
                                "id": {
                                    "type""string"
                                },
                                "uri": {
                                    "type""string"
                                },
                                "etag": {
                                    "type""string"
                                },
                                "type": {
                                    "type""string"
                                }
                            }
                        },
                        "FirstUniqueAncestorSecurableObject": {
                            "type""object",
                            "properties": {
                                "__deferred": {
                                    "type""object",
                                    "properties": {
                                        "uri": {
                                            "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"
                                                            }
                                                        }
                                                    },
                                                    "Alerts": {
                                                        "type""object",
                                                        "properties": {
                                                            "__deferred": {
                                                                "type""object",
                                                                "properties": {
                                                                    "uri": {
                                                                        "type""string"
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    },
                                                    "Groups": {
                                                        "type""object",
                                                        "properties": {
                                                            "__deferred": {
                                                                "type""object",
                                                                "properties": {
                                                                    "uri": {
                                                                        "type""string"
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    },
                                                    "Id": {
                                                        "type""integer"
                                                    },
                                                    "IsHiddenInUI": {
                                                        "type""boolean"
                                                    },
                                                    "LoginName": {
                                                        "type""string"
                                                    },
                                                    "Title": {
                                                        "type""string"
                                                    },
                                                    "PrincipalType": {
                                                        "type""integer"
                                                    },
                                                    "Email": {
                                                        "type""string"
                                                    },
                                                    "Expiration": {
                                                        "type""string"
                                                    },
                                                    "IsEmailAuthenticationGuestUser": {
                                                        "type""boolean"
                                                    },
                                                    "IsShareByEmailGuestUser": {
                                                        "type""boolean"
                                                    },
                                                    "IsSiteAdmin": {
                                                        "type""boolean"
                                                    },
                                                    "UserId": {
                                                        "type""object",
                                                        "properties": {
                                                            "__metadata": {
                                                                "type""object",
                                                                "properties": {
                                                                    "type": {
                                                                        "type""string"
                                                                    }
                                                                }
                                                            },
                                                            "NameId": {
                                                                "type""string"
                                                            },
                                                            "NameIdIssuer": {
                                                                "type""string"
                                                            }
                                                        }
                                                    },
                                                    "UserPrincipalName": {
                                                        "type""string"
                                                    }
                                                }
                                            },
                                            "RoleDefinitionBindings": {
                                                "type""object",
                                                "properties": {
                                                    "__deferred": {
                                                        "type""object",
                                                        "properties": {
                                                            "uri": {
                                                                "type""string"
                                                            }
                                                        }
                                                    }
                                                }
                                            },
                                            "PrincipalId": {
                                                "type""integer"
                                            }
                                        },
                                        "required": [
                                            "__metadata",
                                            "Member",
                                            "RoleDefinitionBindings",
                                            "PrincipalId"
                                        ]
                                    }
                                }
                            }
                        },
                        "AttachmentFiles": {
                            "type""object",
                            "properties": {
                                "__deferred": {
                                    "type""object",
                                    "properties": {
                                        "uri": {
                                            "type""string"
                                        }
                                    }
                                }
                            }
                        },
                        "ContentType": {
                            "type""object",
                            "properties": {
                                "__deferred": {
                                    "type""object",
                                    "properties": {
                                        "uri": {
                                            "type""string"
                                        }
                                    }
                                }
                            }
                        },
                        "GetDlpPolicyTip": {
                            "type""object",
                            "properties": {
                                "__deferred": {
                                    "type""object",
                                    "properties": {
                                        "uri": {
                                            "type""string"
                                        }
                                    }
                                }
                            }
                        },
                        "FieldValuesAsHtml": {
                            "type""object",
                            "properties": {
                                "__deferred": {
                                    "type""object",
                                    "properties": {
                                        "uri": {
                                            "type""string"
                                        }
                                    }
                                }
                            }
                        },
                        "FieldValuesAsText": {
                            "type""object",
                            "properties": {
                                "__deferred": {
                                    "type""object",
                                    "properties": {
                                        "uri": {
                                            "type""string"
                                        }
                                    }
                                }
                            }
                        },
                        "FieldValuesForEdit": {
                            "type""object",
                            "properties": {
                                "__deferred": {
                                    "type""object",
                                    "properties": {
                                        "uri": {
                                            "type""string"
                                        }
                                    }
                                }
                            }
                        },
                        "File": {
                            "type""object",
                            "properties": {
                                "__deferred": {
                                    "type""object",
                                    "properties": {
                                        "uri": {
                                            "type""string"
                                        }
                                    }
                                }
                            }
                        },
                        "Folder": {
                            "type""object",
                            "properties": {
                                "__deferred": {
                                    "type""object",
                                    "properties": {
                                        "uri": {
                                            "type""string"
                                        }
                                    }
                                }
                            }
                        },
                        "LikedByInformation": {
                            "type""object",
                            "properties": {
                                "__deferred": {
                                    "type""object",
                                    "properties": {
                                        "uri": {
                                            "type""string"
                                        }
                                    }
                                }
                            }
                        },
                        "ParentList": {
                            "type""object",
                            "properties": {
                                "__deferred": {
                                    "type""object",
                                    "properties": {
                                        "uri": {
                                            "type""string"
                                        }
                                    }
                                }
                            }
                        },
                        "Properties": {
                            "type""object",
                            "properties": {
                                "__deferred": {
                                    "type""object",
                                    "properties": {
                                        "uri": {
                                            "type""string"
                                        }
                                    }
                                }
                            }
                        },
                        "Versions": {
                            "type""object",
                            "properties": {
                                "__deferred": {
                                    "type""object",
                                    "properties": {
                                        "uri": {
                                            "type""string"
                                        }
                                    }
                                }
                            }
                        },
                        "FileSystemObjectType": {
                            "type""integer"
                        },
                        "Id": {
                            "type""integer"
                        },
                        "ServerRedirectedEmbedUri": {},
                        "ServerRedirectedEmbedUrl": {
                            "type""string"
                        },
                        "ContentTypeId": {
                            "type""string"
                        },
                        "ComplianceAssetId": {},
                        "Title": {},
                        "DocumentType": {},
                        "ContactName": {},
                        "ID": {
                            "type""integer"
                        },
                        "Created": {
                            "type""string"
                        },
                        "AuthorId": {
                            "type""integer"
                        },
                        "Modified": {
                            "type""string"
                        },
                        "EditorId": {
                            "type""integer"
                        },
                        "OData__CopySource": {},
                        "CheckoutUserId": {},
                        "OData__UIVersionString": {
                            "type""string"
                        },
                        "GUID": {
                            "type""string"
                        }
                    }
                },
                "ParentFolder": {
                    "type""object",
                    "properties": {
                        "__deferred": {
                            "type""object",
                            "properties": {
                                "uri": {
                                    "type""string"
                                }
                            }
                        }
                    }
                },
                "Properties": {
                    "type""object",
                    "properties": {
                        "__deferred": {
                            "type""object",
                            "properties": {
                                "uri": {
                                    "type""string"
                                }
                            }
                        }
                    }
                },
                "StorageMetrics": {
                    "type""object",
                    "properties": {
                        "__deferred": {
                            "type""object",
                            "properties": {
                                "uri": {
                                    "type""string"
                                }
                            }
                        }
                    }
                },
                "Folders": {
                    "type""object",
                    "properties": {
                        "__deferred": {
                            "type""object",
                            "properties": {
                                "uri": {
                                    "type""string"
                                }
                            }
                        }
                    }
                },
                "Exists": {
                    "type""boolean"
                },
                "IsWOPIEnabled": {
                    "type""boolean"
                },
                "ItemCount": {
                    "type""integer"
                },
                "Name": {
                    "type""string"
                },
                "ProgID": {},
                "ServerRelativeUrl": {
                    "type""string"
                },
                "TimeCreated": {
                    "type""string"
                },
                "TimeLastModified": {
                    "type""string"
                },
                "UniqueId": {
                    "type""string"
                },
                "WelcomePage": {
                    "type""string"
                }
            }
        }
    }
}

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 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.



Our flow ran successfully. Now we will check the last step of the flow and its value which is returned as output.

As you can see the outputs, these users are having read access to SharePoint Document for Shinchan Gupta_F65E17EE89F5EA11A815000D3A5306E5 record.



Hope it helps...







Comments

Popular posts from this blog

Read Only Sub Grid & Editable Sub grid in Dynamics 365

Using Pipelines in Power platform for deploying solutions to environments.

Understanding Sales Process in D365.