简体   繁体   English

无法以编程方式启动SharePoint工作流

[英]Trouble to start SharePoint workflow programmatically

I've got some failing while trying to start my workflow. 尝试启动我的工作流程时出现了一些故障。 It's a workflow with some approval tasks on it. 这是一个带有一些批准任务的工作流。 That's what happens whenever I try to start it programmatically. 每当我尝试以编程方式启动它时,就会发生这种情况。 I get no errors. 我没有错误。 Everything goes fine. 一切顺利。 However, just when the first approval process walks in, SharePoint starts the approval task as it was told to do. 但是,仅在第一个批准过程进入时,SharePoint便开始执行批准任务。 Then, right after this task gets cancelled, the workflow crashes. 然后,在取消该任务之后,工作流崩溃。 I don't know why. 我不知道为什么 On the workflow history page, I got this information "Error-The workflow could not update the item, possibly because one or more columns for the item require a different type of information.-Unknown error". 在工作流历史记录页面上,我收到此信息“错误-工作流无法更新该项目,可能是因为该项目的一个或多个列需要另一种信息。-未知错误”。 PS: Whenever I start this same workflow manually (through the workflow's start page) with same account, same list item, same everything, it gives me no trouble. PS:每当我使用相同的帐户,相同的列表项,相同的内容手动(通过工作流的起始页)手动启动此相同的工作流时,就不会遇到麻烦。 I tried digging through the log to find something that would help me to solve this but no success. 我尝试在日志中进行挖掘,以找到可以帮助我解决此问题的方法,但没有成功。 Do you have any guess why I can't start it programmatically without facing this? 您是否有疑问,为什么我不面对这一点就无法以编程方式启动它?

My code: 我的代码:

        using (SPWeb Web = SPContext.Current.Web)
        {
            SPList myList = Web.Lists["MyList"];

            SPListItem listItem = myList.GetItemById(ListItemId);

            //Get workflow’s Id             
            Guid workflowId = GetRelatedWorkFlowId(Web);

            foreach (SPWorkflowAssociation workflow in myList.WorkflowAssociations)
            {
                if (workflow.Id == workflowId)
                {
                    using (SPSite site = Web.Site)
                    {
                        Web.AllowUnsafeUpdates = true;
                        SPSecurity.RunWithElevatedPrivileges(delegate()
                        {
                            site.WorkflowManager.StartWorkflow(listItem, workflow, workflow.AssociationData);
                        });
                    }
                }
            }
        }

我试图从通用处理程序(.ashx)进行所有这些操作,并且由于要启动工作流,所以确实回发了它,这使我的工作流崩溃了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM