Thursday, April 1, 2010

Multi Purpose Workflow

Is it possible to write a workflow that can be triggered for many entities in CRM.
The answer is yes. You can do that.

Rather than writing several workflows to get this done you can write one workflow and then use a variable for flag here.

I have listed below a sample workflow.

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)

Guid ID1 = ((SDK.Lookup)base.GetValue(ID1Property)).Value;
string Type = ((String)base.GetValue(TypeProperty));
Guid _iID = Guid.Empty;

switch (Type)
case "1":
_iID = ((SDK.Lookup)base.GetValue(iIDProperty)).Value;
case "2":
_iID = ((SDK.Lookup)base.GetValue(pIDProperty)).Value;
case "3":
_iID = ((SDK.Lookup)base.GetValue(qIDProperty)).Value;
case "4":
_iID = ((SDK.Lookup)base.GetValue(fIDProperty)).Value;

IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));
IWorkflowContext context = contextService.Context;

catch (Exception ex)

return ActivityExecutionStatus.Closed;

as for this example we need to create 4 dependency properties. they are
iIDProperty, pIDProperty, qIDProperty, fIDProperty.

depending on what we get for the switch statement the relevant dependency property would get updated.

No comments:

Post a Comment

Retrieving Calendar of a Bookable Resource in Dynamics

There are occasions where we need to retrieve working days and working times of a resource in Dynamics grammatically. This is quite possible...