使用用户帐户启动工作流程

时间:2017-03-06 07:54:10

标签: c# sharepoint sharepoint-workflow

目前正在使用以下c#代码启动工作流程

 private static void StartWorkflow(SPListItem listItem)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate ()
            {
                using (SPSite elevatedSite = new SPSite(listItem.Web.Site.ID))
                {
                    using (SPWeb elevatedWeb = elevatedSite.OpenWeb(listItem.Web.ID))
                    {
                        elevatedWeb.AllowUnsafeUpdates = true;
                        SPWorkflowManager manager = elevatedSite.WorkflowManager;
                        SPListItem elevatedListItem = elevatedWeb.Lists.TryGetList(listItem.ParentList.Title).GetItemById(listItem.ID);
                        foreach (SPWorkflow workflow in manager.GetItemWorkflows(elevatedListItem))
                        {
                            SPWorkflowAssociation wfAssoc = elevatedListItem.ParentList.WorkflowAssociations.GetAssociationByName(workflow.ParentAssociation.Name, System.Globalization.CultureInfo.CurrentCulture);
                            elevatedListItem.Web.Site.WorkflowManager.StartWorkflow(elevatedListItem, wfAssoc, wfAssoc.AssociationData, true);
                            elevatedListItem.Update();
                        }

                        // Get the workflow by name that's associated with the list item
                        elevatedWeb.AllowUnsafeUpdates = false;
                    }
                }
            });
        }

这将使用系统帐户启动工作流程。有没有办法,我可以使用列创建的列表项来启动工作流程?我想使用特定用户帐户启动工作流程。

1 个答案:

答案 0 :(得分:0)

做了一些RND我得到了问题的解决方案。我们需要将用户令牌传递给Web对象。这是我的答案

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='TransactionLinksTabContainer']/ul/li[4]/div[text()='Admin']")));
WebElement element = driver.findelement(By.xpath("//*[@id='TransactionLinksTabContainer']/ul/li[4]/div[text()='Admin']"))
element.click();