views:

214

answers:

3

Hi,

I am trying to develop a custom activity for my sharepoint workflow that would simplify some things. Within it I create a task, log, set a custom workflow status (setState) and some other things.

The problem I have is with the setState activity which needs the workflowToken that is available in main workflow only. I've found the following blog post: http://blog.sharepoint.ch/2009/11/how-to-set-correlation-token-property.html that explains how to create a property that you can then assign workflowToken to and that works well, however I don't know how can I then set this token that I receive to the setState activity?

In designer it looks that I can't and when I tried to do programmatically like this:

private void setState_MethodInvoking(object sender, EventArgs e)
{
            SetState s = (SetState)sender;
            s.CorrelationToken = WorkflowToken;

}

in the invoking call I get the following error:

This operation can not be performed at runtime.    at System.Workflow.ComponentModel.DependencyObject.SetValueCommon(DependencyProperty dependencyProperty, Object value, PropertyMetadata metadata, Boolean shouldCallSetValueOverrideIfExists) 
   at System.Workflow.ComponentModel.DependencyObject.SetValu

Any ideas?

A: 

The correlation token should be bound at design-time in visual studio, using the properties window (F4).

x0n
Exactly, the token should be assigned at design time, so the WF runtime can use that token to couple caller and callee at runtime. More info here: http://blogs.msdn.com/sharepoint/archive/2006/11/23/developing-workflows-in-vs-part-3-five-steps-for-developing-your-workflow.aspx
Colin
the whole point of the question was that the token CANNOT be assigned at design time for custom activities... if you need the workflowtoken that is, and not a tasktoken.
Robert Ivanc
A: 

Looked around a bit more to get you some more in depth info and found the following answer to a similar question on the MS community forums. It explains what the correlationToken is and how it is used:

The activity needs to have the correlation token of the workflow itself, i.e. the correlation token of the onWorkflowActivated activity. As correlation tokens are design time properties, they cannot be set at runtime, but only in the constructor or via property binding. You can set the correlation token of the activity in the constructor of your workflow, which is the easiest solution, but has some drawbacks. I described a solution on how to cretae a custom activity which has a correlation token property which is bindable against the correlation token property of your workflow here.

Colin
+1  A: 

Duh, I completely overlooked the fact that in the article I've linked to the answer is already there:

public CorrelationToken WorkflowCorrelationToken
{
    get { return (CorrelationToken)base.GetValue(WorkflowCorrelationTokenProperty); }
    set
    {
        base.SetValue(WorkflowCorrelationTokenProperty, value);
        **sendEmail.CorrelationToken = value;**
    }
}

One sets the correlation property in the setter! Oh well!

Robert Ivanc