Sometimes you need to work with the URL of your CRM within Power Automate, for example:
- to relate or unrelate two records with the Common Data Service (current environment) connector
- or writing an email with a hyperlink to a record.
If you have a multi-staged environment and you build your Flow solution aware, you don’t want to update your static URLs after each transport.
Solution
‘Recycle’ the OData Id from a previous CDS action.
- We need an previous CDS action that has an OData Id within its output (like shown above).
If you have no action like this, consider to create a “List records” action which is limited to 1 by the “Top count” option. - Create a “Compose” action and give it the OData_Id as input.
- Create an other “Compose” action and give it following expression to receive the CRM URL.
concat(join(take(split(outputs('OData_Id'), '/'), 3), '/'), '/')
- Create an other “Compose” action and give it following expression to receive the OData URL.
concat(join(take(split(outputs('OData_Id'), '/'), 6), '/'), '/')
How it works
concat(join(take(split(outputs('OData_Id'), '/'), 3), '/'), '/')
Contains the OData Id we’ve stored in the first “Compose” action."https://yourcrm.crm4.dynamics.com/api/data/v9.1/cdi_postedform(792189BA-BA04-E711-80F6-C4346BAC4DDC)"
concat(join(take(split(outputs('OData_Id'), '/'), 3), '/'), '/')
Cuts the URL string in separate substring wherever a slash (‘/’) is.0: "https:"
1: ""
2: "yourcrm.crm4.dynamics.com"
3: "api"
4: "data"
5: "v9.1"
6: "cdi_postedform(792189BA-BA04-E711-80F6-C4346BAC4DDC)"concat(join(take(split(outputs('OData_Id'), '/'), 3), '/'), '/')
Merge the first 3 entries of the splitted URL to a new array.0: "https:"
1: ""
2: "yourcrm.crm4.dynamics.com"concat(join(take(split(outputs('OData_Id'), '/'), 3), '/'), '/')
Merge the new array into a string and separate the entries by a slash (‘/’)."https://yourcrm.crm4.dynamics.com"
concat(join(take(split(outputs('OData_Id'), '/'), 3), '/'), '/')
Create a new string with the merged URL and put a slash (‘/’) at its end."https://yourcrm.crm4.dynamics.com/"
In the same way you receive the OData URL when you “take” the first 6 elements instead of the first 3 elements.