Getting SharePoint Document URL In Dynamics 365 CE

Introduction


Sometime we are required to get the full path of the image which we have uploaded to a SharePoint document for a specific entity. In this article I am going to demonstrate how Microsoft Flow can be used to implement this requirement. Feel free to comment if there is another easy way of doing this.

This article is assuming you have basic understanding of Dynamics 365 CE Share Point integration and Flow and that Share Point integration is already configured. Keep in mind this is for demo purposes but you can change it according to your requirement.
 

Details

 
Let’s add a string field in the Contact entity where we are going to store the  URL, our field look like below:
 
Getting SharePoint Document URL In Dynamics 365 CE
 
Now Navigate to Flow and use the ollowing steps,
 
> Click on New and select automatic flow having following trigger
 
Getting SharePoint Document URL In Dynamics 365 CE
 
> Let’s name our flow as “Set Image URL For Contact” and set action properties like below,
 
Getting SharePoint Document URL In Dynamics 365 CE
 
> Now let’s add some variable which we require for formatting URLs, Click on + New Step and search for variable and select Initialize Variable. In this variable we are going to set our Share Point Site URL.
 
Getting SharePoint Document URL In Dynamics 365 CE
 
> Add another integer type variable, where we are to store last index of “/” in URL, it should look like the following,
 
Getting SharePoint Document URL In Dynamics 365 CE
 
In the above expression I am using following formula
 
lastIndexOf(triggerBody()?[‘{Path}’],’/’)
 
> Add another variable and call it Folder path, we will be setting this variable at later stage
 
Getting SharePoint Document URL In Dynamics 365 CE
 
> We need other variables to store image extensions like you can use the following to validate specific file extensions based on your requirement.
 
Getting SharePoint Document URL In Dynamics 365 CE
 
We are using following formula in the above variable
 
last(split(triggerBody()?[‘{FilenameWithExtension}’], ‘.’))
 
> Add a condition and add condition to check folder and file extension like following
 
Getting SharePoint Document URL In Dynamics 365 CE
 
> Now under yes, below, first we are going to set folder path, this step may vary based on your entity name,
 
Getting SharePoint Document URL In Dynamics 365 CE
I am using the  following formula to set variables:

substring(triggerBody()?[‘{Path}’],8,sub(variables(‘lastindex’),8))
 
Above 8 is count of entity +1 so for example cotnact/ will be 8
 
> Next we need to query document location record based on the folder path, we can use Dataflex (Common Data Service current) connector. Select List records and set its property like the following:
 
Getting SharePoint Document URL In Dynamics 365 CE
In the above we are going to query Document Locations record based on the Folder Path variable.
 
> Finally add an Update action from Dataflex (Common Data Service current) connector and set its properties like following
 
Getting SharePoint Document URL In Dynamics 365 CE
 
Apply to each loop will be automatically applied when we will set field returned from Document Location record step. Finally our flow should look like below
 
Getting SharePoint Document URL In Dynamics 365 CE
 
Finally try to upload image to your entity you should see image URL populated after some time
 
Getting SharePoint Document URL In Dynamics 365 CE
 

Summary


So if you  need file name with extension or need the path of the file you can use the above Flow to store file name in CRM.
 
Hope it will help someone!

Keep learning, Keep sharing !!


Similar Articles
HIMBAP
We are expert in Microsoft Power Platform.