Thursday, June 7, 2007

Creating Custom Action for SharePoint Designer Workflow problem

First let me start by saying I am not going to tell you how to create a custome action. There are many available examples online that you can find, and I may be publishing a little "how to" myself in the future.

For those of you who created a custom action, you may or maynot have noticed that when you do a custom activity, configure it to use Lookup fields on field configured as DesignerType="StringBuilder" and instead of field value you get [%_x005f_String0%] you need to "tell" SharePoint to replace your tokens (look up fields) with the actual values on that workflow.

A good example was when I was trying to develop an action that will work like the "send email" action, only included some changes.

I got this error in the "body" field of the email i wanted to send.

The solution is rather easy to implement and consists of 2 steps:
1 - First you have to define a new property to your activity - the workflow context:

public static DependencyProperty __ContextProperty = DependencyProperty.Register("__Context", typeof(WorkflowContext), typeof(EmailActivity));

public WorkflowContext __Context
return (WorkflowContext) base.GetValue(__ContextProperty);
base.SetValue(__ContextProperty, value);

2 - Second you will have to your Execute method:

protected override ActivityExecutionStatus Execute(ActivityExecutionContext provider){
Activity parent = provider.Activity;
while (parent.Parent != null)
parent = parent.Parent;

string returnValue = Helper.ProcessStringField(stringToProcess, parent, this.__Context));

You don't want to know how I learned that, so don't ask...

1 comment:

Anonymous said...

Thank's. It works.