Making SharePoint site URL/folder path dynamic in Power Automate connector (D365/SharePoint Integration)

There are situation when you need to go dynamic with the parameters, and with multiple instances to deploy making the power automate flow connectors to be dynamics is a challenge. Setting the SharePoint URL and folder path parameters in SharePoint connector is one example to make it dynamic. If we hardcode those parameters in the connector it is a challenge and hassle when we are deploying it to multiple environments. There are multiple ways we can achieve those parameters to be dynamic. Here I am planning to discuss possible ways to get it done, if I missed out something feel free to point the other alternatives as well.

“None of us, including me, ever do great things. But we can all do small things, with great love, and together we can do something wonderful.”

Mother Theresa

Solution 1 – (Hardcoding involved)

Introduce a environment variable for site URL and folder paths. Then get that environment variable in the flow and set those parameters. Make sure you always get the current version instead of the default environmental variable definition.

Pros:

  • Don’t need to do much work other than steps to retrieve the environment variable.
  • No code needed

Cons:

  • It is still hardcoded, need to specify the current value of the Environmental Variable in each instances. Though it is one time, still it isn’t dynamic.
  • The steps to get the Environmental Variable in the flow is also quite a steps to be configured.

Solution 2 – (Easy but still not that great)

First list the SharePoint Sites using the Dataverse connector. Use the defaultsite eq true filter to get the default SharePoint site. Using the absolute URL field you will get the SharePoint site URL. Below is the setup you can use.

Now that the site URL is dynamic, we found a way to make the folder path (relative) also dynamic. In the below setup, I list the Document Locations for the record and you can add in whatever logic to get the Document Locations (if there are multiple locations involved). Using the document location id, called in a custom bound action that will return the absolute URL of the record folder path in SharePoint. Now that we have site and record absolute URL, using the string replace to trim of the site URL and we get the relative URL path. Other way these logic can be added in the custom action itself to reduce steps in the flow.

replace(variables('SharpointAbosoluteUrl'),variables('SharepointSiteUrl'))

Pros:

  • It is dynamic and you don’t need to hardcode anything.
  • Easy solution transition from one environment to another.

Cons:

  • Need a bit of coding involved for the custom action bit.

Solution 3 – (So far the better option)

The third and my final option (as said feel free to teach me your way) I would say is that, instead of the custom action used in the previous solution use the in built CRM function to get the absolute URL and site collection in a one go.

https://docs.microsoft.com/en-us/previous-versions/dynamicscrm-2016/developers-guide/mt622429(v=crm.8)?redirectedfrom=MSDN

To trigger the API using the HTTP with Azure AD connector.

Selecting that connector will ask for the below two options, select the second one which is Invoke and HTTP request.

In the next stage it ask for Base URL and Azure AD URL. Don’t panic, use the base CRM URL in both the parameters. (https://{ORG}.crm.dynamics.com/), then click on Sign in.

The final step will look like below.

Pros:

  • All the steps are configurable and no code involved.
  • More dynamic.

Cons:

  • I didn’t see any 😀
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s