I recently upgraded one of my custom workflow activity plugins to CRM 2011 and thought it would be an interesting exercise to walk through that process with you. So let’s walk through the changes, from top to bottom.
As with any application that communicates with CRM, you need to reference the CRM SDK assemblies:
Creating Parameters for the Activity
This activity accepts 4 parameters, one of which was required. In this example, we are:
- “Decorating” a Lookup property to show the label “Marketing List” in the Workflow user interface.
- The parameter is required
- Since it is a lookup, the lookup is referencing the list Entity, which is a Marketing List.
With CRM 4.0 developers were generally targeting the .NET Framework v3.0 (or3.5), so to define an input parameter looked something like this:
In the .NET Framework 4.0, the parameter definition is slightly condensed:
The class definition has changed slightly due to the change in Windows Workflow versions. Beside the base class changing from SequenceActivity to CodeActivity, you will notice the CRM 2011 version does not have the “decorations” that specify the group and name that will be displayed within the CRM workflow editor. More on that later.
[CrmWorkflowActivity("Remove from Marketing List", "CRM Accelerators")]
public class RemoveFromMarketingList: SequenceActivity
public class AddToMarketingList : CodeActivity
The Execute method remains the sole method required for a custom workflow activity though the Context parameter and return value have changed.
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
protected override void Execute(CodeActivityContext executionContext)
Connecting to CRM
The code that defines the connection to the CrmService has changed slightly as well, but overall, the concepts remain the same:
- Get the Execution Context
- Get a handle to the Workflow Context or Organizational Service Factory
- Create an instance of the CrmService
IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));
IWorkflowContext context = contextService.Context;
ICrmService crmService = context.CreateCrmService();
IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
Accessing Parameter Values
Accessing the values found within the input parameters is slightly different in CRM 2011 where the value of the parameter is not actually extracted until you actually need to use it. In CRM 4.0, that process happens more or less automatically due to the DependencyProperty setup.
Guid ListId = MarketingListLookup.Value;
Guid ListId = MarketingListEntityReference.Get<EntityReference>(executionContext).Id;
Doing the Work
After you have all of the above code in place, the remainder of your code should function as it did in CRM 4.0. I did not have to make any changes to my code once the “plumbing” was upgraded.
Registering your Plugin
The registration process is exactly the same between versions: You use the Plugin Registration Tool.
The biggest difference between the two is in CRM 2011, the Plugin Registration Tool is where you specify how the custom workflow activity is displayed to the user within the workflow editor.
When you highlight the workflow activity, you need to specify the FriendlyName, Name, and WorkflowActivityGroupName properties as shown below:
Note: Even though the above figure doesn’t show it, the FriendlyName and Name properties need to be the same.
Well, that is about it. It probably only took me 2 hours to perform the upgrade of my code and that was starting from scratch with zero knowledge of the process. I just reviewed the SDK documentation and sample code and worked through each issue as it was encountered.
I hope this helps and good luck.