CRM 2011 – Custom Workflow Syntax changes from CRM 4 to CRM 2011

[tweetmeme source=”BenHosk” only_single=false]

I am always interested in articles describing the differences between developing in CRM 4 and CRM 2011.  This is a common problem I have and it actually works both ways.

To start with I was trying to convert code examples in Javascript and Plugins from CRM 4 to CRM 2011 and finding that we use Entity instead of DynamicEntity etc.  The Javascript is completely different so I’m not going to mention that but if you want to know click the link below.

I also find myself getting confused when I have to do some coding in CRM 4 because I get used to working CRM 2011 and then I have to remember how to do things in CRM 4 again…

Here are the current syntax comparison blogs I have written

CRM 2011 – Syntax changes in plugins from CRM 4

CRM 2011 – Comparison between CRM 4.0 and CRM2011 script

Type Mapping Between Versions CRM 2011 and CRM 4

Now today I found this article explaining the differences between custom workflows in CRM 4 and CRM 2011, it’s an excellent article and the original can be found here but I have pasted the full article below because I would like it for my own reference


Differences in Custom Workflow Assembly in CRM 4.0 and CRM 2011

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.

 

CRM 4.0

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)

 

CRM 2011

protected override void Execute(CodeActivityContext executionContext)

4. Create service

CRM 4.0

IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));

IWorkflowContext context = contextService.Context;

ICrmService crmService = context.CreateCrmService();

CRM 2011

IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();

IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();

IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

5. INPUT Parameters

CRM 4.0

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

CRM 2011

Declaration: how to initialize the input parameter

[Input(“Enter Case “)]

[ReferenceTarget(“incident “)]

[Default(“3B036E3E-94F9-DE11-B508-00155DBA2902″, ” incident “)]

public InArgument<EntityReference> CaseID { get; set; }

Use: Access the input parameter declared above as,

Guid caseid = CaseID.Get<EntityReference>(executionContext).Id

6. OUTPUT  Parameters

CRM 4.0

[CrmOutput(“outputSum”)]

public CrmMoney Sum

{

get

{

return (CrmMoney)base.GetValue(SumProperty);

}

set

{

base.SetValue(SumProperty , value);

}

}

CRM 2011

[Output(“outputSum”)]

[Default(“23.3”)]

public OutArgument<Money> Sum { get; set; }

11 thoughts on “CRM 2011 – Custom Workflow Syntax changes from CRM 4 to CRM 2011

  1. bharathreddysheelam June 8, 2011 / 9:39 pm

    Hi,
    we are using CRM 3.0 and from workflow we are calling .net programs (.net assembly to run some methods). Now we are upgrading to CRM 2011. Can you please point me to some information which lets me know how to make this happen.

    Thanks
    Bharath

    Like

    • Hosk June 8, 2011 / 9:44 pm

      I’m not sure you can upgrade from crm 3 to crm 4, you might have to go in a couple of steps of up grading to CRM 4 and then CRM 2011.

      I will have a look at this and probably do a blog post later this week on the subject, so check the blog

      Like

  2. carlosaugustoalves August 9, 2011 / 3:22 pm

    Very good, Please what I insert in “Enter Case” in case below.

    [Input(“Enter Case “)]

    [ReferenceTarget(“incident “)]

    [Default(“3B036E3E-94F9-DE11-B508-00155DBA2902″, ” incident “)]

    public InArgument CaseID { get; set; }

    Like

  3. Ruben P. April 2, 2012 / 10:25 am

    thank you Hosk, this really helped!

    Like

  4. Madhu August 7, 2015 / 10:47 am

    Good to Go Through

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s