Friday, December 12, 2008

Your first Dynamics CRM WorkFlow Activity

This post show should act as a guideline to creating you first workflow activity dll for Dynamics CRM. It includes some gotachas I came across so hopefully it will save you some time.

Create a new workflow activity library in Visual Studio




You need to reference the CRM Micrsoft.Crm.Sdk and , Micrsoft.Crm.Sdk.TypeProxy dlls in your project.








Rename the class to a suitable name and add the lines
using Microsoft.Crm.Sdk;
using Microsoft.Crm.SdkTypeProxy;
using Microsoft.Crm.Workflow;

Add a decorator [CrmWorkflowActivity("MyFirstWorkFlowActivity", "ConcatStrings")] to the class which will determine how it appears to the user in CRM and add the the method below

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) {return base.Execute(executionContext); }

Now sign the project at which point the bones of your workflow activity are in place.











In our example we will take two string parameters and and conconatate them into an ouput parameter add the code below. The decorator CrmInput and CrmOutput attributes determine which properties are visible in the CRM workflow editor. A property can be be set to both CrmInput and CrmOutput if required.




In our example we will take two string parameters and and conconatates them into an ouput parameter so add the code below

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
this.outString = this.inString1 + ", "+this.inString2 ;

return base.Execute(executionContext);
}


public static DependencyProperty inString1Property = DependencyProperty.Register("inString1", typeof(string), typeof(MyFirstCRMActivity));


[CrmInput("InString1")]


public string inString1
{
get { return (string)base.GetValue(inString1Property);}
set { base.SetValue(inString1Property, value);}
}


public static DependencyProperty inString2Property = DependencyProperty.Register("inString2", typeof(string), typeof(MyFirstCRMActivity));
[CrmInput("InString2")]


public string inString2
{
get { return (string)base.GetValue(inString2Property);}
set { base.SetValue(inString2Property, value); }
}


public static DependencyProperty outStringProperty = DependencyProperty.Register("outString", typeof(string), typeof(MyFirstCRMActivity));
[CrmOutput("OutString")]
public string outString
{
get { return (string)base.GetValue(outStringProperty);}
set { base.SetValue(outStringProperty, value); }
}



Build the project and copy the dll and pbl file to the C:\Program Files\Microsoft Dynamics CRM Server\Server\bin\assembly (assuming default install)


You now need to regsiter the DLL however do not use the registration tool that comes with the SDK use the version from
http://blogs.msdn.com/crm/archive/2008/02/04/crm-registering-plug-ins-made-easy.aspx




Once registered you can create a workflow in CRM which calls the new created dll
setting the input parameters in the first step and the output in the second



<


Gotchas - Here are a few problems you may come across


If you cannot publish your Workflow from CRM turn tracing on and check the trace logs

http://support.microsoft.com/kb/907490


Check if namespace and class the same as this will prevent the workflow from been published


ErrorCode: -2147201023 - the type in the dependency property is not correct


When redeploying you may need to stop and restart IIS and the CRM Asynch service so you can use a batch file or build script to execute the following
net stop w3svc
net start w3svc
net stop MSCRMAsyncService
net start MSCRMAsyncService

Another common problem

Could not create activity of type 'CorrespondenceWorkflowActivity.Correspondence'. System.ArgumentException: Type 'CorrespondenceWorkflowActivity.Correspondence' does not define a static dependency property with name 'inGuidProperty'.

http://blogs.catalystss.com/blogs/scott_seely/archive/2007/03/06/96.aspx

Tuesday, December 09, 2008

Dynamics CRM 5.0

If you want to have a look at the next version of CRM download the “The Appealing Business Application” presentation from the PDC 2008 and jump to 45 mins in

This covers the new UI, form layout and customization solutions. Learn who you will be able to create a base customization solution and lock it down allowing additional customizations to be made on top.

Saturday, December 06, 2008

Batch file to logon to Microsoft CRM as different users

If you want to run CRM as a different user to the logged on user either use the following line at the command prompt or copy it into a batch file. Change the userID and CRM server accordingly

runas /user:JoeGill "C:\Program Files\Internet Explorer\iexplore.exe http://localhost:5555/loader.aspx"

It is useful for demos to show different users at the same time.

Tuesday, December 02, 2008

SharePoint MTUG Talk 1st Dec 2008



Well done to Martin and Micheal who gave a great talk on SharePoint last night. There were almost 40 attendees there although Michael reckons its was 140!. There was so much to cover we could have run a series of talks on Sharepoint.

Thanks to perpetuum and Microsoft for sponsering the event


Monday, December 01, 2008

CS0433

If you are using Dynamic Data in ASP.NET to generate some basic entry web site you will get this error if you publish your web site and you have a form with the same name as a table in you data context class. e.g. Order.aspx and System.Data.Linq.Table Order.

No problem when running fron VS which sent me up the wrong path initially