D365 Blog by Matt. ©2018

Word Templates - Advanced Features

February 9, 2019

 

In the first two parts to this blog series, we learned how to create a simple letter/mailmerge as well as Quotes using repeating lines in a table. These are some of the basics which you can build upon to create more complex Word Templates.

 

One thing we haven’t touched on yet is automation, how can we automate any of these processes and bring some value added to your D365CE enviroment.

 

An example you might want to use would be to generate reports of Opportunities on an Account. Maybe this is a key Account for an account manager and they want to run weekly reports or maybe they have projects and want a list of Projects for this Account. We can build a Word Template to pull through some information about an Account and then use the repeating data in a table to show a list of related records.

 

As I’ve covered how to do these things in my previous posts, I’ll let you go back and read them. :)

 

To generate a Word Template, you need to go to the command bar when in any record which supports Word Templates or on any view of an entity which does. You can automate the production of Word Templates by using a Workflow Action.

 

You can determine whatever trigger you like for the Workflow, change of a field, changing a record from draft to active, or on a re-occuring schedule. Create a Workflow that runs in the background, set your triggers and now we need to add a step to the workflow.

 

In the add a step, choose Perform Action. When you get this step added to your workflow, from the drop down, scroll down to the “Command Actions” section and choose SetWordTemplate. Click Set properties.

 

 

 

 

 

From here, choose your Word Template from the SelectedTemplate field and then the Target is going to be your record, so in the look for box in the right, choose you record. In my example, it would be {Account(Account)}.

 

Save and activate your workflow. When it runs on the record you selected the Word Template will be put as an Attachment in the notes with all the correct data populated! Simple.

 

From here users can pick it up, check that it’s correct, convert it to a PDF and send it in an email. But doesn’t that seem like a little too much work for a user? Yes, we best look at some more automation.

 

If you have read my blog for a while or follow me on social media, you will know I’m an advocate of using other PowerPlatform technologies to help achieve a solution. As D365CE, PowerApps and Flow are all on the same platform, it makes things really simple with little/no code solutions. I have been using a solution for a little while using the OneDrive for business convert to PDF function which I first saw on Bruce Sithole’s blog www.bruce365.com, you should totally read his blog and follow him on twitter @365Bruce. However, while writing this article, a new Flow action for Word Templates has been released by Microsoft.

 

It starts off with checking when a record is created. What we are looking for is when a note is created.

 

 

Then we check to see what the note is regarding and if the note is an attachment. You can specify other criteria, if you could have multiple attachments on the same entity. You could use file name, if these may have a common naming convention.

 

 

@and(equals(triggerBody()?['isdocument'], true),

equals(triggerBody()?['_objectid_type'], 'accounts'),

not(contains(triggerBody()?['filename'], '.pdf')))

 

 

What the above query is represents is a check to see if the note is a an attachment (isdocument = true) AND where the note is regarding an account (_objectid_type = accounts) AND where the file name does not contain .pdf. This last bit helps prevent an infinite loop but we have something else which helps later on.

 

To build the above query, I didn’t just think about it, I did it an easier way. I build the query using the basic mode to get the lines, then combine the two and wrap it in a @and clause. Below are some examples.

 

 

 

 

 

The above will help you for now but a new query editor is coming to Flow which will behave a lot more like an advanced find.

 

Next we want to go down the Yes part of the condition and add some actions.

 

 

 

The first thing I like to with most flows it retrieve the record details, as this Flow runs on Notes, and what we want is details of the Account the note is attached to. I do this so I can use this data later on.

 

 

 

Next I’m going to copy the Word Template to OneDrive for Business in a specific Location, but you could also use something like SharePoint to store the file. I’ve created a temporary location and this is going to be a temp file.

 

 

 

Then we use the new Word Flow action of convert template to PDF.

 

 

 

Next we are going to delete the original note/attachment. This will also help prevent an infinite loop.

 

 

 

Then we create a new record, in the document part we use the content from the Word template conversion (find this in the dynamic content menu), you can rename the file from here and the most important part is to specify the regarding so that it attaches back to the correct record. I renamed the file using details from the account, which is why I did the Get Record action at the start.

 

 

 

I do some tidying up and delete the file we copied to OneDrive.

 

 

 

What you should end up with is a new pdf back in your note section of D365 .

 

 

 


The above solution, I have found, provides really value to a user/company as it can automate Reports/Proposals/Quotes. I used this quite often to create Quotes for Customers, automatically convert to PDF and attach back to Dynamics. From there sales people can pick up the quote to email out.

 

There are ways to extend this solution even further, you could create an email to send the attachment to a customer from the Flow, however, doing so would lose the tracking/visibility of the email being sent.

 

You can create an email in Dynamics using a Workflow and then use North 52 or Workflow Utilities  to pick up the attachment in the notes and attach to the email and then this can either be saved as a draft for users to check and send out. This method does allow you to see if the email was sent by all users who look at the timeline/social pane, allows for users to check the email before it’s sent and will also track replies, providing that setting is turned on for Dynamics.

 

Ciao for now!

 

Please reload

Recent Posts

Please reload

Archive

Please reload

Tags