Creating a no-code workflow for CRM 4.0 with Visual Studio 2005 (2008)

New in CRM 4.0 is the possibility to build custom workflows using Windows Workflow Foundation (WF). WF is the programming model, engine and tools for quickly building workflow enabled applications on CRM 4.0. In previous version of CRM the engine was limited and not as robust. WF is a standard component used in many other products (MOSS, Biztalk ect).

Business rule example
-when an Opportunity is created a check is done and if estimated value is greater than 100000 a task is created and associated to the opportunity. Schedule end date is set to same as opportunity estimated close date. No rocket science and just an example... I would like to see an example of integration with MOSS or other document library. Once I'm back from my parental leave and I have the time I might publish something.

Workflow from VS2005sp1
Flow from Visual Studio 2005 sp1.

In the workflow policy (TaskValues) I set the values for my reminder task and this is the only code needed.

this.ReminderTask = Microsoft.Crm.Workflow.CrmWorkflow.CreateEntity("task")
this.ReminderTask["subject"] = string.Concat("Please follow Up on Opportunity ", this.PostImageOpportunity["name"])
this.ReminderTask["scheduledend"] = this.PostImageOpportunity["estimatedclosedate"]
this.ReminderTask["description"] = "Automatic Task generated from Workflow. Please add your own notes here."

this.OpportunityId = Microsoft.Crm.SdkTypeProxy.CrmTypes.CreateLookup(Microsoft.Crm.SdkTypeProxy.EntityName.opportunity.ToString(),
this.ReminderTask["regardingobjectid"] = this.OpportunityId 

The final result on my Opportunity

Opportunity workflow runned

Click on the Activites I would see my "reminder task".
NOTE! Since the default view is on next 30days you need to change the view to "all" else you won't see you task.

Links related to subject

Windows Workflow Foundation on MSDN

Dynamics on MSDN
SharePoint Server 2007 SDK: Software Development Kit
Windows SharePoint Services 3.0: Software Development Kit (SDK)
VS 2005 extensions for .NET 3.0
Microsoft .NET Framework 3.0 Redistributable Package
Visual Studio 2005 extensions for .NET Framework 3.0 (Windows Workflow Foundation)
Microsoft Virtual Labs


The Visual Studio project is attached below and for instructions how-to publish the workflow please see the CRM 4.0 SDK.

This posting is provided "AS IS" with no warranties, and confers no rights.