We have listed the list of changes noticed for designing a custom workflow assembly in CRM 2011 and in CRM 4.0.
1. References
CRM 4.0
using System.Workflow.Activities;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Compiler;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.Sdk.Query;
using Microsoft.Crm.SdkTypeProxy;
using Microsoft.Crm.Workflow;
CRM 2011
using System.Activities;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Workflow;
2. Base Class
Base class definition has been changed from SequenceActivity to CodeActivity.
CRM 4.0: In CRM 4.0 we have to specify both Workflow name and Workflowactivitygroupname in the code as written in the following code.
[CrmWorkflowActivity("My Custom Workflow", "CRM Workflow")]
public class MyCustomWF: SequenceActivity
CRM 2011: In CRM 2011 that is done in different way.
public class MyCustomWF: CodeActivity
Both Workflow name and Workflowactivitygroupname can be specified at the time of registering the assembly as shown in below screen shot.
3. Execute Method
The overridden Execute method remains the same except parameter and return type.
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
protected override void Execute(CodeActivityContext executionContext)
4. Create service
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);
5. INPUT Parameters
Declaration: how to initialize the input parameter
// specified dependency property
public static DependencyProperty CaseIDProperty = DependencyProperty.Register("CaseID", typeof(Lookup), typeof(TotalTaskRetrieval));
// Specified Input property
[CrmInput("Enter Case ")]
// Set the reference Target for Property created
[CrmReferenceTarget("incident")]
// Property Defined for caseId
public Lookup CaseID
{
get
return (Lookup)base.GetValue(CaseIDProperty);
}
set
base.SetValue(CaseIDProperty, value);
Use: Access the input parameter declared above as,
Guid caseid=CaseID.Value
[Input("Enter Case ")]
[ReferenceTarget("incident ")]
[Default("3B036E3E-94F9-DE11-B508-00155DBA2902", " incident ")]
public InArgument<EntityReference> CaseID { get; set; }
Guid caseid = CaseID.Get<EntityReference>(executionContext).Id
6. OUTPUT Parameters
[CrmOutput("outputSum")]
public CrmMoney Sum
return (CrmMoney)base.GetValue(SumProperty);
base.SetValue(SumProperty , value);
[Output("outputSum")]
[Default("23.3")]
public OutArgument<Money> Sum { get; set; }
Hope this helps!!!