DEV Community

Cover image for Get SharePoint location for Dataverse record
Kinga
Kinga

Posted on

Get SharePoint location for Dataverse record

SharePoint document management for Dataverse offers numerous advantages. But while accessing documents and their locations via a model-driven Power Platform app is straightforward, retrieving them using Power Automate can be quite challenging.

If you need to archive attached documents in a different location or send them all via email as attachments, you must first locate the SharePoint Online (SPO) library and folder associated with the entity.

Get SharePoint location for record

The "Get SharePoint location for record" flow uses the Document Location Dataverse table to gather details about the attachment location, such as the Relative URL (folder name) and sharepointdocumentlocationid.

Once SharePoint integration with Dataverse is configured for an entity, an entry pointing to the library in SharePoint is added. Note that the library name is based on the table logical name:

document location

Only when the first document is attached to a record, additional entry is created in the Document Location table , referencing a folder in the SharePoint library. The folder name is based on the record properties:

document location for a record

The above values are not enough to access the SharePoint location where the documents are stored, but can be used in a call to the RetrieveAbsoluteAndSiteCollectionUrl() Dataverse function to obtain the SharePoint Online site collection URL:

/api/data/v9.2/sharepointdocumentlocations(sharepointdocumentlocationid)/Microsoft.Dynamics.CRM.RetrieveAbsoluteAndSiteCollectionUrl()

The flow then executes a series of SharePoint REST api calls to obtain a full set of information, like

parameter name description example
tenant_name the URL of the tenant's root site; also used as a hostname when retrieving SPO site using GUID. contoso.sharepoint.com
site_url The URL of the current SharePoint site, as defined in the site URL parameter. https://contoso.sharepoint.com/sites/XYZ
site_title Title of the current SPO site Project XYZ
site_id The id of the current SPO site in a guid format. xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
web_id The id of the current SPO web object in a guid format. yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy
library_absolute_url The full URL of the library. https://contoso.sharepoint.com/sites/XYZ/idapps_externalcloudservice
library_name The RootFolder. Used in the URL, is generated automatically and cannot be changed by users. It can be changed with PowerShell. idapps_externalcloudservice
library_title The title of the library. This property can be changed by the user. The Archive Library
library_id Library's id in a guid format zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz
library_drive_id Used by Graph API when referencing libraries. b!S3SdNSBmTUGa4v5ffh_rslLJssoXH4xEuShkEO-uxKg9bblUMeoaTbQC5t69DJ-x
folder_absolute_url absolute url of a SPO library folder associated with the current teams channel https://contoso.sharepoint.com/sites/XYZ/idapps_externalcloudservice/test01_5437302CBC7A4D96AFD9BDFDAF15EF7F
folder_display_name display name of the folder; white spaces are not encoded test01_5437302CBC7A4D96AFD9BDFDAF15EF7F
folder_drive_id driveItem Id for the folder. Can be used in MS Graph API Get driveItem 01JEVXUVBDVF6ZMUFRM5B34EGLOEDAUF5B
folder_id SPO list item id. Can be used in SharePoint REST API, or MS Graph API Get listItem 15
error_message The error message if any of the actions failed, or empty string. {"Error":"..."}
success True or False

You may download the solution with Power Automate workflow including the above examples from Power Automate Utils GitHub repo.

Top comments (0)