Many times, when we use word template in dynamics crm to generate a template, we customer want the word template to be in pdf format rather than word which obviously seems more professional to send to their consumers and can’t be edited directly.
Unfortunately, so far, out of the box crm doesn’t have any tool to get the pdf file from generated word file for any record, but now we have Microsoft flow for our rescue.
In this post,we’ll see how we can generate a word template using a workflow and how can we get the word template file converted into pdf format using microsoft flow.
We have Invoice summary word template which customer run on invoice record to generate Invoice summary for customer in word format. We want to convert it into pdf format.
Part A: Creating workflow in crm to generate word template on record
Create a UI workflow in crm as shown below. In add step select perform action:
After step 1, workflow will look as shown below.
Click on set properties as select word template and primary field of the entity:
We have kept this workflow on demand only of testing purpose. You can configure it to fire on the event you want as per your requirement.
Now, activate your workflow.
Step A4 (Testing the workflow):
This workflow, when run on an invoice record, will generate a word file from selected template and attach in the notes section as shown below:
Part B: Creating a Microsoft flow to convert this word file from notes into pdf
Step B1: Go to https://flow.microsoft.com and select Dynamics365 as start the service for your flow.
Then select when a record is created as the trigger of your flow as shown below:
Step B2: Now select your crm instance and entity name as notes and check if the file name equals Invoice Summary.docx (same as the file generated by workflow)
STEP B3: Now on Yes part of result of condition, select One drive for business as the connector and select create File as the action.
In create one drive file :
- Select a path where file will be stored
- set a file name
- Type base64ToBinary function in expression and then from Dynamics content select document field of “When a record created” step (notes record which triggered the flow) and set this as file content.
Step B3: In this step again select one drive for business connector and select convert file as the action. Here you have to pass unique Id of the file we just created in one drive in last step as the parameter.
Step 4B:Now create a notes record in crm with the file we just converted in last step.
Set Title and file name with .pdf extension as shown in below screenshow. For document, just set “body(‘Convert_file’)[‘$content’]” in expression and click update.
Basically here Convert_File is the name of last step. Change “body(‘Convert_file’)[‘$content’]” to “body(‘Convert_docx_file_to_pdf_in_onedrive’)[‘$content’]” if your last step’s name is “Convert docx file to pdf in onedrive”.
For regarding, set regarding value of notes record created and regarding type as Invoice.
Now to save up extra space, delete the .docx file created in one drive as well as the docx file created in crm.
Step 6B: One done, your flow will look as below . I have changed steps label for better understanding.
Just save it now.
Now it’s time to test the whole setup. Just run the on demand workflow on an invoice record and wait for some time. you’ll see a pdf record attached in notes section of your record as shown below:
So this was how you can convert word template to pdf.
Now you can use this pdf file attached in notes to send to customer in email. So the whole process of sending pdf of word template can be done on a single button click event on crm form.
Few imp Points :
- You can also use Azure logic apps, (Both ms flow and azure logic apps are licence based services)
- As per my logic, this flow will trigger on each notes record creation. This can be optimize keeping in mind under licence have limited number of flow run per month.
Hope it was helpful…!!!
Excellent Information. Thanks