R – getting workflowToken into a custom activity in sharepoint

sharepointworkflow

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?

Best Answer

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!