SharePoint:在 StartWorkflow() 终止后访问工作流变量
我通过调用workflowManager.StartWorkflow() 以编程方式从SharePoint 事件接收器运行SharePoint 工作流。
工作流在执行过程中设置一些工作流变量。有没有办法在工作流终止后访问这些变量的最后一个值(例如,对 StartWorkflow() 的调用返回)?
这是我的示例代码,展示了我的意图:
public override void ItemAdded(SPItemEventProperties properties)
{
SPWorkflow workflow = null;
SPWorkflowManager workflowManager = null;
try
{
base.ItemAdded(properties);
workflowManager = properties.OpenWeb().Site.WorkflowManager;
var workflowAssociation = properties.ListItem.ParentList.WorkflowAssociations[0];
workflow = workflowManager.StartWorkflow(properties.ListItem, workflowAssociation, "<Data></Data>");
// I can read any fields that were updated by the WF
SPListItem item = properties.ListItem.ParentList.GetItemById(properties.ListItemId);
string validationResult = (string) item["ValidationResult"];
// how can I access any workflow variables created during execution?
}
catch (Exception ex)
{
Debug.WriteLine(ex);
if (workflow != null && workflowManager != null)
{
SPWorkflowManager.CancelWorkflow(workflow);
}
throw;
}
}
I am running a SharePoint workflow programmatically from a SharePoint event receiver by calling workflowManager.StartWorkflow().
The workflow is setting some workflow variables during execution. Is there a way to access the last value of these variables after the workflow has terminated (e.g., the call to StartWorkflow() returns)?
Here's my sample code that demonstrates my intent:
public override void ItemAdded(SPItemEventProperties properties)
{
SPWorkflow workflow = null;
SPWorkflowManager workflowManager = null;
try
{
base.ItemAdded(properties);
workflowManager = properties.OpenWeb().Site.WorkflowManager;
var workflowAssociation = properties.ListItem.ParentList.WorkflowAssociations[0];
workflow = workflowManager.StartWorkflow(properties.ListItem, workflowAssociation, "<Data></Data>");
// I can read any fields that were updated by the WF
SPListItem item = properties.ListItem.ParentList.GetItemById(properties.ListItemId);
string validationResult = (string) item["ValidationResult"];
// how can I access any workflow variables created during execution?
}
catch (Exception ex)
{
Debug.WriteLine(ex);
if (workflow != null && workflowManager != null)
{
SPWorkflowManager.CancelWorkflow(workflow);
}
throw;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许将它们写到列表中?这可能是您最不混乱的选择。
或者,有一个 SPWorkflow.Xml 属性“返回一个以 XML 格式表示工作流实例的字符串”,但我从未尝试过。尽管将其传回 SharePoint 可能会很尴尬。
Maybe write them out to a List? This might your least messy option.
Alternatively, there's a SPWorkflow.Xml property that "returns a string that represents the workflow instance in XML format" but I've never tried it out. Though passing this back into SharePoint could be awkward.