Bulk
Execution Workflow
Case
Study: -
Some
time we need to run on demand workflow for selected set of records. This task
need manual intervention. In some scenario
we want to schedule this task on hourly basis or daily basis. In Dynamics CRM there
is no provision for scheduling on demand workflow execution for set of selected
records. Like Dynamics CRM provide provision to schedule Bulk deletion workflow
scheduling.
Solution:
-
In
below solution I will provide a way how we can schedule our bulk on demand workflow
execution.
I
have used below one custom entity to schedule bulk workflow execution.
Entity
Name: -Bulk Execution Task
Below
are the field used in this entity: -
Field name
|
Data Type
|
Fetchxml Query
|
Multiple Lines of Text
|
Last Run Time
|
Date and Time
|
Next Run Time
|
Date and Time(Calculated)
|
Repeat Duration(Hours)
|
Whole Number
|
Termination Date
|
Date and Time
|
Calculated
field: -
Workflow
Used: -
In
this solution a OOB workflow is used name “Bulk Workflow Execution”.
This
workflow will trigger when record is created in “Bulk Execution Task”.
In
this workflow Child process needs to check.
If
record is created and conditions are meet a custom workflow will execute. This
custom workflow responsible to run our on-demand workflow based fetch query we
have specified.
You
can download solution from here: - Download Here
This
solution is created in “Dynamics 365” version.
Working: -
Create
record in Setting->Bulk Execution Workflow->New.
Provide
workflow ID.
Open
your workflow need to execute and copy ID from address bar. Make sure On-demand
is checked for this workflow.
Provide your fetch XML query to select records. You can used “Advance Find” to get fetch query.
Provide other details.
When
you save the record. Your Workflow start execution based on your information.
Click
on follow to keep update from my blogs.
Thank you Santosh for the solution. it works like a charm except I think the bulk execute workflow fails to the 2 min plugin execution time a shown below. if you an interval in the workflow execution process that will avoid the below error
ReplyDeletePlugin Trace:
[BulkWorkflowExecution: BulkWorkflowExecution.Executeworkflow]
[BulkWorkflowExecution (1.0.0.0): BulkWorkflowExecution.Executeworkflow]
Workflow started
Record Count: 90763
Batch execution stated
2
Batch execution Ended
Remaining Records : 89763
Batch execution stated
2
Batch execution Ended
Remaining Records : 88763
Batch execution stated
2
Batch execution Ended
Remaining Records : 87763
Batch execution stated
2
Batch execution Ended
Remaining Records : 86763
Batch execution stated
2
Batch execution Ended
Remaining Records : 85763
Batch execution stated
Error Message:
Unhandled exception:
Exception type: Microsoft.Crm.CrmException
Message: An unexpected error occurred from ISV code. (ErrorType = ClientError) Unexpected exception from plug-in (Execute): BulkWorkflowExecution.Executeworkflow: System.TimeoutException: Couldn’t complete execution of the custom activity BulkWorkflowExecution.Executeworkflow plug-in within the 2-minute time limit.
at Microsoft.Crm.Sandbox.SandboxCodeUnit.ProcessException(Exception originalException, IExecutionContext context, SandboxClient client, SandboxCallTracker callTracker, Boolean isSafeToRetry, DateTime performanceExecutionStartTime, SandboxTracker tracker, Guid parentExecutionId, CrmException& crmException, String& assemblyContents)
at Microsoft.Crm.Sandbox.SandboxCodeUnit.<>c__DisplayClass24_0.b__0()
at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute(ILogger logger, EventId eventId, ActivityType activityType, Action action, IEnumerable`1 additionalCustomProperties)
at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute(ILogger logger, XrmTelemetryActivityType activityType, Action action)
at Microsoft.Xrm.RemotePlugin.CrmProvider.RemotePlugin.Execute(IServiceProvider serviceProvider)
at Microsoft.Xrm.RemotePlugin.CrmProvider.RemotePluginContainer.Execute(IServiceProvider serviceProvider)
at Microsoft.Crm.Workflow.Services.ProxyCustomActivity.Execute(CodeActivityContext executionContext)
-- End stack trace --