List of changes in Custom Workflow Assembly in CRM 4.0 and CRM 2011


Here is a a quick list of changes you need to remember while creating workflow assemblies in CRM 4.0 or CRM 2011, as found here.

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

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; }

 

Advertisements

About Dynamics CRM Guru

We are a group of CRM Consultants and have significant experience in transforming businesses in the right way. We use this platform to share our knowledge which might help many others in the digital transformation journey. We are happy to help you if you are looking for any assistance in CRM implementation projects.

Posted on July 27, 2011, in Microsoft CRM 2011, Microsoft Dynamics and tagged , . Bookmark the permalink. 2 Comments.

  1. i get the follwing error:
    Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Invalid default value: The entity Incident doesn’t exist. Property: Case
    Detail:
    -2147200995

    Invalid default value: The entity Incident doesn’t exist. Property: Case
    2011-08-18T14:42:14.2662846Z

    -2147200995

    Invalid default value: The entity Incident doesn’t exist. Property: Case
    2011-08-18T14:42:14.2662846Z

    Server stack trace:
    at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
    at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
    at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
    at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

    Exception rethrown at [0]:
    at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
    at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
    at Microsoft.Xrm.Sdk.IOrganizationService.Update(Entity entity)
    at Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.UpdateCore(Entity entity)
    at Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.Update(Entity entity)
    at PluginRegistrationTool.RegistrationHelper.UpdateAssembly(CrmOrganization org, String pathToAssembly, CrmPluginAssembly assembly, PluginType[] type) in C:\Users\30000352\Downloads\MicrosoftDynamicsCRM2011SDK (2)\sdk\tools\pluginregistration\RegistrationHelper.cs:line 263
    at PluginRegistrationTool.PluginRegistrationForm.btnRegister_Click(Object sender, EventArgs e) in C:\Users\30000352\Downloads\MicrosoftDynamicsCRM2011SDK (2)\sdk\tools\pluginregistration\PluginRegistrationForm.cs:line 382

    Like

  2. Hi Maggy,

    Sorry for the late reply. These may work. Check and let us know.

    1. If you are using the Early bound programming method, make sure you ‘use’ the namespace of the generated code file in your code.
    2. Add “_service.enableprobytype()” in your code.
    3. The service context name mentioned while generating the Crmsrvcutil should be initiated properly if you are using “Context.UpdateObject(entityname)” or Context.AddObject(entityname)”

    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

%d bloggers like this: