Asynchronous Batch Process Solution Revisited – part 2

In my previous post, I described some of the Asynchronous Batch Process Solution (ABP) version 2 internals. In the next posts, I would like to go through different business scenarios and explain how to use the ABP solution, step by step.

Prerequisites

1. Download the Asynchronous Batch Process Solution, import into Microsoft Dynamics CRM 2015 on-premise/Online organization
2. Go to Settings – > Solutions and Open the ABP solution. Go to the Batch Process entity definition and check the Settings checkbox in the ‘Areas that display this entity’ section
3. Save and publish the solution

As always, I advise against publishing any external solution on your production environment without testing it first.

Target Records Query Scenario

This scenario describes a business logic operation (Action) which is automatically applied to a collection of Microsoft Dynamics CRM records (target records), either once or repeatedly.

Some sample business requirements of this type:

– Send birthday greeting to target Contacts on their birthday date
– Send monthly newsletter to target customers
– Weekly Leads Evaluation – once a week, disqualify all Leads that are more than 5 days old and are not rated ‘Hot’
– Update large collection of records by overriding the 250 records limit (max. grid page size)

Following are the steps to implement the Weekly Leads Evaluation requirement:

1. Create a new Process (Workflow Rule (real-time/background) or Action) targeting the Lead entity and name it ‘Inactive Lead Disqualify’
2. Uncheck all ‘Start when’ trigger checkboxes to prevent automatic triggering of the process
3. If you created a Workflow Rule, check the ‘As an on-demand process’ checkbox and select the correct Scope
4. Add a Check Condition step to test if the Lead record is in an Open status. Add another step to change Lead Status to Cancelled (Disqualified state)
5. Save and activate the process

Define Action Proces

6. Open Advanced Find and define a new query to retrieve all Lead records where Created On date is older than 5 days and are not rated ‘Hot’
7. Click to Edit Columns button and remove all columns to maximize the query efficiency
8. Click the Download Fetch XML button and open the resulting file with some text editor
9. Copy the FetchXML query text to the clipboard

Define Advanced Find query

10. Create a new Batch Process record (Settings –> Batch Processes)
11. Paste the FetchXML query test into the Target Records field
12. Name the Batch Process: Weekly Leads Evaluation Process (or other meaningful name)
13. Set the Activation Frequency to ‘Weekly’
14. Set the Next Activation to any future date and time. I suggest selecting the application’s least busy time
15. Set the Status Reason to ‘Scheduled’
16. Click Save to schedule the Batch Process.

You are done! The Batch Process is set and waiting for the next activation date and time.

Define Batch Process Record

Looking at the Background Processes tab for the Batch Process record, you should notice one waiting Workflow instance which is waiting to retrieve all matching Lead records and to apply the Inactive Lead Disqualify process to each resulting record.

Background processes view

Once the Batch Process was executed once, you will notice that the Next Activation date was rescheduled for one week after the last activation.
If all went right, the Last Activation Completion Status is Success and the Activation Counter is set to 1.

Rescheduled Batch Process record

 

 

If you created a background Workflow Rule, you can view a list of the records that were affected by the batch process execution. To do that, navigate to the Inactive Lead Disqualify workflow rule and click the Process Sessions tab.

Affected records view

If you would like to deactivate the Batch Process scheduling, change the Status Reason value to ‘Suspended’ and save. Since there may already be a Workflow instance scheduled and waiting, go to the Background Processes for the Batch Process record and cancel waiting instances.
This also applies if you change the Next Activation date/time once the Batch Process record is already created and scheduled.

In the next post, I’ll walkthrough the Aggregative Query Scenario.

Advertisements