In this scenario, the business requirement is to automatically create a PDF of a Word document that has been created from a Microsoft Dynamics 365/CRM Template.
We are using the out-of-the-box Invoice template and an Action step in a workflow to generate a Word document that is saved as note on the Invoice entity. Once this step has been completed a North52 Process Genie formula converts the Word document to a PDF using a conversion web service.
This example could easily use a Quick Button to trigger the process to make it even easier for the user, perhaps even creating an email ready to send with the attachment.
North52 Decision Suite Solution
The North52 Decision Suite solution works like this,
- An Action workflow step to create the Word document from a template
- A Process Genie workflow step referencing the formula
- We create a formula of type 'Process Genie' on the Invoice entity
- Create a workflow on the Invoice entity with 2 steps:
- When the Workflow is run a Word document is created using the template and attached to the Invoice record as a Note
- Then the Process Genie formula takes the Word document and using a web service converts it to a PDF and saves the PDF as Note on the Invoice record
- The web service we use to convert the document is https://cloudconvert.com - their free plan offers around 25 PDF documents per day!
North52 Decision Suite Steps
The following set of steps will set this formula up for you.
- Create an account with https://cloudconvert.com to obtain your API key
- Create a new xCache record:
- Set the Category to CloudConvert
- Set the Base Key to CloudConvert_ApiKey
- Set the Value (Secured) field to the API key from your CloudConvert
- Save the xCache record
- Create a new Formula of type Process Genie
- Set the Source Entity to Invoice
- Copy and paste the formula below into the formula canvas
- Save the formula
- Create a new Process:
- Set the Process name to 'Generate Invoice PDF'
- Set the Category to 'Workflow'
- Set the Entity to Invoice
- Uncheck the Run this workflow in the background checkbox
- Click OK
- Check the As an on-demand process
- Set the Scope to Organization
- Uncheck the Record is created checkbox
- Click the Add Step button and select Perform Action
- Set the Action to SetWordTemplate
- Set the Properties as per image below:
- Click the Add Step button and select North52 > N52 Process Genie
- Set the Properties as per image below (using your formula Shortcode):
- Update the descriptions for the workflow steps to something meaningful, and the Activate the Process
- You are ready to test! Go to an Invoice record and run the workflow. Two attachments should be created and added to the Notes - one for the Word Document and one for the PDF
- There are several enhancements you might like to add to this business requirement:
- Delete the Word Document after the PDF has been successfully created to save on storage
- Create an email record and attach the PDF
- Use a QuickButton to enable the process to be triggered directly from the form
Smartflow( SetVar('GetWordDoc', FindValue('annotation', SetFindAnd('objectid', 'filename'), SetFindAnd([invoice.invoiceid], 'Invoice.docx'), 'documentbody', '', true)), CallRestAPI( SetRequestBaseURL('https://api.cloudconvert.com'), SetRequestResource('/convert'), SetRequestDetails('Post'), SetRequestHeaders(), SetRequestParams('apikey', xCacheGetGlobal('CloudConvert_ApiKey'), 'inputformat', 'docx', 'outputformat', 'pdf', 'input', 'base64', 'file', GetVar('GetWordDoc'), 'filename', 'Invoice.docx', 'wait', true, 'download', true), SetRequestAuthenticationNone(), SetRequestFiles(), SetRequestExpected('OK'), SetRequestActionPass( CreateNote('Invoice PDF', 'invoice', [invoice.invoiceid], 'Invoice Generated via North52 at ' + LocalDateTime(), [invoice.invoicenumber] + '.pdf', 'application/pdf', GetVar('file')) ), SetRequestActionFail(ThrowError('PDF Conversion Failed: ' + GetVar('responsecontent'))) ) )
Wizard - xCacheGetGlobal
Did you know?
You can create advanced rules for model driven app navigation (ribbon) buttons
North52's Decision Suite has functionality that we call Quick Ribbon that allows you associate a North52 Formula with a Ribbon button for model driven apps.
You can execute advanced business logic using the North52 business rules engine for Dynamics 365. Scenarios include:
- Click button to clone a record
- Click button to execute a Formula for multiple records in a grid
- Use Formula logic to enable/disable or show/hide a button