Search This Blog

Monday, June 27, 2022

MS CRM: How to convert word template into pdf using Microsoft Flow

 1

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.

Scenario:

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

Step A1:

Create a UI workflow in crm as shown below. In add step select perform action:

1_1.png

Step A2:

After step 1, workflow will look as shown below.

3.png

Click on set properties as select word template and primary field of the entity:

4.png

Step A3:

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.

1.PNG

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:

5.png

 

Part B: Creating a Microsoft flow to convert this word file from notes into pdf

Step B1Go 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:

6.png

7.png

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)

8.png

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 :

  1. Select a path where file will be stored
  2. set a file name
  3. 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.

10.png

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.

11.png

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”.

12.png

For regarding, set regarding value of notes record created and regarding type as Invoice.

13.png

Step 5B:

Now to save up extra space, delete the .docx file created in one drive as well as the docx file created in crm.

14.png

Step 6BOne done, your flow will look as below . I have changed steps label for better understanding.

Just save it now. 16.png

 

Testing:

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:

11

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 :

  1. You can also use Azure logic apps, (Both ms flow and azure logic apps are licence based services)
  2. 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.

No comments:

Post a Comment