Skip to main content

Automate document creation with DCP and Power Automate

Automate Document Creation

Recently I had the requirement to automate document creation with Document Core Packs. You can do this via classic workflows, like explained in this article:


But on the one hand, whenever you open the solution explorer and want to add a new classic workflow, you are presented a message, telling you that classic workflows are already quite outdated and you should have a look at Power Automate.

And on the other hand, this classic workflow references a CRM record (document template), so you will have to reconfigure it in each of your environments, since the template will have a different GUID accross your environments.

So I had a look, how to achive the same via Power Automate.

Trigger

We start with adding a new flow, that triggers on update of a record using the Common Data Service (current environment) connector, since we can define the filtering attributes there, so that our flow doesn't trigger on every update, but only when our attribute of interest is being changed.

In our case we look for a workorder, where the statecode is changed to inactive:

Object Type Code

To generate a document for a record, the mscrm-addon automerge record relies on a link to the underlying record. This link has to be in the same format, like the link created in classic workflows, when you add the "record url". Which means we have to query the object type code of our underlying record.

For some system entities like contact (1), account (2), user (8) a.s.o the object typecode is always the same, but for entities introduced via solutions, e.g. "Field Service" solution or for custom entities, the object type codes can be different accross your environments.

To get the object type code, we have to do a web API call, which means we have to ellaborate our CRM url first.

This is done by initializing  a variable with following formula:


Then we add an "Invoke http webrequest" action, where we call the web api to get the object type code for our record, in our case the msydn_workorder entity:


Finally we intialize another variable where we assemble our record URL:

Document template

As a next step we have to fetch our document template, by adding a list records action and searching for the document template based on its name and entity:

Create Document

Then we create a mscrm-addons auto merge item to create the document, by addind a CDS create record action. We choose the auto merge action, define a name, add the record URL:

choose the format:

and the template:


Do until

Then we have to wait until the document has been created. In classic workflows you would have defined a wait condition, while in Power Automate you achieve this with a "do until" action. The do until action queries your auto merge record until it reaches statecode inactive:

Attach document

Finally, when your document has been created, you have another create record step, where you create another mscrm auto merge item, that attaches the created document as a note to the underlying record.

We choose auto merge action "Attach to Entity" and add the record url:

and we link the created document

At the end you could also add steps to clean up the auto merge items created by this flow. Or you define a recurring bulk delte job that regularly cleans up these items.


Comments

  1. When i try to attached image, show error, I don't know why. Then i try Delimiti. Its an other great option for automate document creation and for build contracts using forms.
    Thanks

    ReplyDelete

Post a Comment

Popular posts from this blog

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 C

Send e-mails with a link to the record via Power Automate

Today we gonna have a look at how to send an e-mail with a link to a CDS record via Power Automate. In the good old classic workflows, you could directly reference the "record URL" from the dynamic data. But since UCI has been launched and you have the possiblity to target different apps, you already had to do a few more steps in the classic workflows as well. The URL to a CDS record consists of multiple things: CRM URL appid entity name record id So we will work this out one after the other. First we add a "List record" action to lookup the appid of the app, we target. We look for "model driven apps" and filter by the name of the app: Then we initialize a variable with the resulting app id: Then we initialize another variable and extract the CRM_URL: Then we fetch our records, where we want to send out a notification with a link, in this case we look for workorders fullfilling certain criteria: Now we compose the record URL: As a next step we create a new

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 365 Common Data Service Common 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&