Of late I face a problem where I had to execute an asynchronous process from a plugin. I was faced with multiple option like using asynchronous plugin or a workflow etc . After careful investigation of both the alternatives I came to the conclusion that my business process is much suited for a workflow rather than an asynchronous plugin. Now the only real challenge was to call a workflow from a plugin code. After a bit of investigation of SDK I can across the following sdk ExecuteWorkflowRequest Class. This class allows you to execute on demand workflow using plugin.
C#
ExecuteWorkflowRequest ewfr =
new
ExecuteWorkflowRequest();
//each workflow has its own unique GUID. This GUID can be used to specify which workflow needs to be executed
ewfr.WorkflowId =
new
Guid(
"A68490BF-ABCD-1234-CDA1-1234567890AB"
);
// Replace the guid with your flow GUID
//Now all we need to do is specify the GUID of the record on which this workflow needs to be execute
ewfr.EntityId =
new
Guid(
"09876543-1234-ABCD-BCDE-E123457541BA"
);
ExecuteWorkflowResponse resp = (ExecuteWorkflowResponse)service.Execute(ewfr);
VB
Each workflow has its own unique GUID. This GUID can be used to specify which workflow needs to be executed
Now all we need to do is specify the GUID of the record on which this workflow needs to be execute
Dim
ewfr
As
New
ExecuteWorkflowRequest()
With
{
WorkflowId = new Guid(
"A68490BF-ABCD-1234-CDA1-1234567890AB"
),
EntityId = new Guid(
"09876543-1234-ABCD-BCDE-E123457541BA"
)
}
Replace the guid with your flow GUID
Execute the workflow.
Dim
response
As
ExecuteWorkflowResponse =
CType
(_serviceProxy.Execute(ewfr), ExecuteWorkflowResponse)
Further reading
http://msdn.microsoft.com/en-in/library/microsoft.crm.sdk.messages.executeworkflowrequest.aspx
Hope this helps