getting workflowToken into a custom activity in sharepoint
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 ru开发者_高级运维ntime. at System.Workflow.ComponentModel.DependencyObject.SetValueCommon(DependencyProperty dependencyProperty, Object value, PropertyMetadata metadata, Boolean shouldCallSetValueOverrideIfExists)
at System.Workflow.ComponentModel.DependencyObject.SetValu
Any ideas?
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!
The correlation token should be bound at design-time in visual studio, using the properties window (F4).
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.
精彩评论