Skip to main content

Power Automate Get absolute Sharepoint URL from document location

Document Locations

If you enable Sharepoint document integration in your model driven apps, you can define for which entities the possibility to upload documents to sharepoint shall be offered and you can define a folder structure.

Possible folder structures can either be based on account or contact, which means if you create child items (e.g. opportunities, activities, ...) sub folders are created below.

If an entity is enabled for document management a "Files" tab is added to the form of your model driven app and as soon as you click on that tab a folder is automatically generated on Sharepoint.

Once the folder has been created you have options to create new or upload existing file or to open the document location (folder) on Sharepoint:


What happens behind the scenes is, as soon as you click on the files tab your model driven app checks, weither a "document location" for this item already exists, or not.

The document location is an own entity in CDS, that acts as the connecting part between CRM and Sharepoint:


It stores information like the regarding record, the relative url (= folder) and the parent document location (= parent folder):


So if you have e.g. a structure based on account, you would have multiple document locations, like:
parent site > account  > account name _ guid > opportunity > topic _ guid ... and all of them just store the relative url.

Identify absolute URL

But what happens under the hood if you click on "Open document location"? How does Dynamics generate the absolute URL of the underlying Sharepoint location?

For that purpose an own Web API function called RetrieveAbsoluteAndSiteCollectionUrl exists. This function returns the absolute Sharepoint url and the url of the site collection.

Power Automate - Get absolute Sharepoint URL

Some time ago I blogged about how to upload e-mail attachments from CRM to Sharepoint using Power Automate / Flow: http://crmaddicted.blogspot.com/2020/01/working-with-email-attachments-in-power.html

What I did not describe back then was, how to setup the necessary document locations in CRM or identify the absolute URL of existing sharepoint locations, e.g. if you have to move certain folders on Sharepoint.

This is something I've been working on the last days and it looks like that:

I check using a "List records action" weither a document location already exists for an opportunity, or not:


If the folder exists, I invoke an http request and call the web api function RetrieveAbsoluteAndSiteCollectionUrl to get the absolute URL of the underlying Sharepoint folder, like that:

<CRM URL>/api/data/v9.1/sharepointdocumentlocations(<GUID of documentlocation>)/Microsoft.Dynamics.CRM.RetrieveAbsoluteAndSiteCollectionUrl()

Then I parse the JSON and get the absolute URL and site collection URL:


Based on that information I can work out the url of the sharepoint site, the document library or the folder, depending on what input your sharepoint action needs (e.g. create file, move folder, ...):






Comments

Popular posts from this blog

Working with Optionset lables in Power Automate

Connector Types Power Automate currently offers 3 different connectors, to connect Power Automate with your Dynamics 365 instance: Dynamics 365Common Data ServiceCommon Data Service (current environment) Today we will look on ways how to retrieve option set labels via the different connectors, for our sample accounts:

Dynamics 365 This connector should not be used any more, since in April 2019 it has been announced as being deprecated.
https://flow.microsoft.com/en-us/blog/nine-new-connectors-in-april-and-improved-visibility-into-trigger-failures/
With the Dynamics 365 connector it was quite easy to work with optionsets, since it offered both the optionset value (int) and the optionset label (name) in the dynamic content:

And here we go, these are our results:

Common Data Service Since the Dynamics 365 connector has been deprecated, this is the connector you should use.
If you perform a "Get record" or "List records" action, the optionset value and the optionset lab…

Working with email attachments in Power Automate

CDS connector There are many blogs explaining how to fetch email attachments from CRM and uploading them to Sharepoint using the old Dynamics 365 connector. But since this connector has been announced as deprecated in April 2019, I tried to achieve the same using the Common Data Service connector.
My use case is to upload e-mail attachments to sharepoint, in case an e-mail contains attachments and it is linked to an opportunity.
So first we define the following trigger:

Then we add a condition to check, weither the e-mail is linked to an opportunity:

As a next step we query all attachments related to this e-mail, but wait there are two entities called "attachment" offered:

So let's try the first one:

And what we get back is some metadata about the attachment, but not the filename and the body of the attachment, we are looking for:

But at least we are a step closer to our attachments. Lets try the second "attachment" entity offered in the list/get records actio…