SharePoint:在 StartWorkflow() 终止后访问工作流变量

发布于 2024-09-07 06:34:32 字数 1326 浏览 6 评论 0原文

我通过调用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清秋悲枫 2024-09-14 06:34:32

也许将它们写到列表中?这可能是您最不混乱的选择。

或者,有一个 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文