NOTE: This article describes the creation of a classic scheduled workflow. For a similar example that demonstrates the creation of a scheduled payment reminder using Microsoft Flow, please see here.
With the option to schedule document operations inside Microsoft Dynamics CRM, DocumentsCorePack opens up its capabilities for scheduled reports.
Whether you wish to…
- …get a simple overview of all opportunities closed last month,
- …send a reminder to a group of selected customers automatically, or
- …find a printed copy of all invoices every morning in your printer,
with scheduled reports this is not only possible, it is also easy.
This article describes which preconditions are needed in order to run the tool and provides a step-by-step instruction of how to use the scheduler.
How does the scheduler work?
The Scheduler allows you to define queries for CRM records where a certain workflow is executed by following a defined schedule.
You will need the following components to operate the scheduler:
- DocumentsCorePack workflow integration, which allows for automatic document generation and processing inside MS CRM workflows, and
- The Mscrm-addons.com Scheduler entity, which allows for workflows to be scheduled
Step-by-Step: Defining a scheduled report
Step 1: Creating the workflow
In our example, we would like to create a workflow that would remind all customers with outstanding bills automatically via email.
To begin, we will need to create a new process by navigating to Settings > Processes and clicking on the New button.
NOTE: If you have not created a workflow in Microsoft Dynamics CRM yet, please see the following articles here:
The Create Process window opens. Enter a suitable ❶ process name for your process and set the ❷ category to “Workflow” and the ❸ entity to Invoice. Click OK once you are finished to proceed.
A new window will appear. This is where we will configure the steps for our workflow.
Step 2: Adding steps to our workflow
Next, we’ll need to add steps to our workflow. In our example, we want to create a document, attach it to an email, and send it. To do that, we will need to create five steps in the following order:
- Create a document
- Wait for document generation
- Create an email
- Attach document to email
- Send email
Create a document
To create our first step, click on the Add Step dropdown and select Create a Record.
Then, set the record to be created to MSCRM-ADDONS.com AutoMergeWorkingItems. Click on Set Properties once it’s been set.
You will be prompted to configure the MSCRM-ADDONS.com AutoMergeWorkingItems record, which is the record type responsible for generating documents. Enter a ❶ name for your record and set the ❷ AutoMergeAction to CreateDocument. Underneath, select the ❸ template that should be executed.
On the right side of the window, the ❹ PrimaryRecordUrl should be set to the dynamic record URL from the Invoice entity. This can be located in the second dropdown as shown below. The ❺ SaveAs field should be set to PDF. Save and close the window once you’re done. This will add the step to the workflow.
Wait for document generation
The next step will be a wait condition. Adding this step will cause the workflow to wait until the document generation has finished. This will be important, as later, we will need the GUID of the created document, which will only be available once the document has been generated.
The wait condition will also need to be configured. Open the configuration window and click on the dropdown. Select the previous step (under “Local Values”), then set each subsequent dropdown to Status, Equals, and Inactive respectively. This will ensure that the workflow will wait until the status of the record is inactive.
Save and close this window after the settings have been entered.
Create an email
Add another Create a record step underneath the wait condition. This time, set the record type to Email.
Fill out the email information, including the From, To, Subject, and email body.
Attach document to email
After saving, add another Create Record step, selecting the MSCRM-ADDONS.com AutoMergeWorkingItems record again. In the properties window, enter a name and set the AutoMergeAction to AttachToEmail.
With this action set, navigate to the Attach To Email section of the record. Set the EmailToAttach field to the email message created in the previous step. It can be added by selecting the email step in the upper dropdown, then “Email Message” field in the lower dropdown.
Similarly, in the DocumentGUID field, add the GUID of the created document by selecting the step where it was generated in the upper dropdown, then the “CreatedDocument” field in the lower one. Save and close this window once finished.
Send email
For our last workflow step, create one last Create Record step, setting the record once more to MSCRM-ADDONS.com AutoMergeWorkingItems. When opening the properties window, name the record and set the AutoMergeAction to SendEmail.
In the EmailToSend field under Send Email, add the EmailToAttach field, which can be retrieved from our previous step. Save and close the window once you are done.
Our finished workflow looks like the following:
Save the workflow and activate it. This will prepare our flow to be used by our scheduler.
Step 3: Creating a scheduler
With our workflow finished, the last thing we must do is create our scheduler. This can be done by creating a new MSCRM-ADDONS.COM Scheduler record (an entity that comes with the installation of DocumentsCorePack).
Note: You can use Advanced Find to create a new MSCRM-ADDONS.COM Scheduler record when searching for the entity.
To enable the scheduler, you’ll need to configure the following fields:
- Name: Enter a name for the scheduler
- Status Reason: Set the status reason to either active or scheduled. In this case, it should be set to scheduled. Setting it to active will trigger the scheduler manually upon save.
- Execution Amount: Set how often the scheduler should be triggered.
- Next Execution Date: The next date in which the scheduler will be triggered. This can be manually adjusted.
- Workflow: The workflow that should be run. In our case, the scheduler will run the workflow we just created.
- Fetch: The FetchXML to be applied over the scheduler. It is used to filter which records the scheduler should run for.
Since we only want the scheduler to run for outstanding bills, we will need a fetch that will retrieve only those invoices.
Creating a fetch
We can create a fetch by utilizing Advanced Find. If, for example, we ❶ search for invoices with a due date from the last seven days, we can then ❷ download the fetch used to get those results.
With the fetch created, we can then copy and paste the fetch into the Fetch field within the scheduler. Once saved, the scheduler will be activated.
That’s it! We appreciate your feedback! Please share your thoughts by sending an email to support@mscrm-addons.com.