Four Nested If Limitations on workflows in CRM.


Hi,

We recently had a requirement to write a workflow that would require nested if conditions. Much to our surprise we realized that only 4 nested if conditions are supported.

After selecting “Select this row for “IF 5″and clicking on “Add Step”, we can see the Add Step menu greyed out.

The workaround is to use Child Workflow.

Check out this wonderful article

http://www.wipfli.com/BlogPost_MCRM_blog_10_14_09.aspx

Hope it helps.

Passing Parameters to Workflow from Host Application `


To pass parameter to Workflow.

First we need to create a local variable and property in the workflow class.

private string _message = string.Empty;

public string Message

{

get { return _message; }

set { _message = value; }

}

From our hosting application to pass the value for the parameter,

we need to create a generic Dictionary object which uses String for key and Object as value for the parameter.

Key for parameter should exactly match the public property in the workflow.

Dictionary<String, object> wfParam = new Dictionary<string, object>();

wfParam.Add(“Message”, “My Hello World”);

Now we need to pass this Dictionary object to the workflow using one of the overloaded method for CreateWorkflow

WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(HelloWorldWorkflow.Workflow1),wfParam );

Bye…

Understanding a Hello World program in Windows Workflow Foundation


Hi,

1. Create a new Sequential Workflow Console Application project.

2. Open Workflow1.cs in design mode.

3. Drag a Code activity to the workflow at (Drop activities to create a sequential workflow)

4. Select Code activity and in the properties window for ExecuteCode property write MyMessage and the press enter twice, which will create a method with the same name.

private void MyMessage(object sender, EventArgs e)
{
Console.Write(“Hello World”);
Console.ReadLine();
}

5. Press F5 to run the project.

This completes our first program in windows workflow foundation.

What we have done over here is that

We have created a console application which is hosting a workflow. Workflow requires an application as a host. It could be a console application, windows forms application,

asp.net application and even a Windows service.

We can found the code used for hosting the workflow in Program.cs.

Let’s try to understand the code

// First we are creating an instance of WorkflowRuntime

// WorkflowRuntime – is responsible for starting our workflow, firing events for different situations

// while the task is executing.

using(WorkflowRuntime workflowRuntime = new WorkflowRuntime())

{

// Our application and the workflow, both are running on different threads.

// We need our application to wait long enough before our workflow either gets completed or terminated(due to error).

// For this AutoResetEvent is used.

// Here an instance of AutoResetEvent is created i.e. waitHandle

// calling waitHandle.WaitOne() will make the main thread to wait until it is signalled using

// waitHandle.Set(), which will be done when workflow either gets complete or gets terminated.

AutoResetEvent waitHandle = new AutoResetEvent(false);

 

// Here anonymous method is used to declare an event handler for WorkflowCompleted event

// Once workflow gets completed, the main thread is signalled to proceed further through

// waitHandle.Set()

workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)

{waitHandle.Set();};

 

// Here anonymous method is used to declare an event handler for WorkflowTerminated event

// Once workflow gets completed, the main thread is signalled to proceed further through

// waitHandle.Set(), which releases the console application from its wait

workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)

{

Console.WriteLine(e.Exception.Message);

waitHandle.Set();

};

 

// Workflow instance is composed of one or more activities. WorkflowRuntime executes these workflow instances.

// workflowRuntime.CreateWorkflow->Creates a workflow instance and if the workflow runtime hasn’t been started

// the CreateWorkflow method calls StartRuntime method of WorkflowRuntime

WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(HelloWorldWorkflow.Workflow1));

 

//Starts the execution of the worflow instance

instance.Start();

 

// The main thread waits till it is signalled to proceed further i.e. waitHandle.Set()

waitHandle.WaitOne();

}

Bye…