简体   繁体   English

Sharepoint 2010 以编程方式启动工作流错误

[英]Sharepoint 2010 start workflow programmatically error

I have a workflow associated with a content type.我有一个与内容类型相关的工作流。 I try to kick it off from code from within the event receiver on the same content type, so when an item is updated, if there is a certain condition (status = ready for review) I start it.我尝试从事件接收器中相同内容类型的代码中启动它,因此当更新项目时,如果存在特定条件(状态 = 准备审查),我将启动它。

//This line does find the workflow association //这一行确实找到了工作流关联

var assoc = properties.Web.ContentTypes["Experiment Document Set"]
         .WorkflowAssociations.GetAssociationByName("Experiment Review Workflow",
          ultureInfo.CurrentUICulture);

//I had tried to use this line from something I found online, but it would return null //我曾尝试使用我在网上找到的东西中的这一行,但它会返回 null

assoc = properties.Web.WorkflowAssociations
     .GetAssociationByName("Experiment Review Workflow",
      CultureInfo.CurrentUICulture);

The next line gives an error:下一行给出了一个错误:

var result = properties.Web.Site.WorkflowManager
                       .StartWorkflow(properties.ListItem, assoc,string.Empty,
                                      SPWorkflowRunOptions.Synchronous);

System.ArgumentException: Workflow failed to start because the workflow is associated with a content type that does not exist in a list. System.ArgumentException:工作流无法启动,因为工作流与列表中不存在的内容类型相关联。 Before re-starting the workflow, the content type must be added to the list.在重新启动工作流之前,必须将内容类型添加到列表中。

To check this, I was looking at the content type of the list item being updated and it is correct为了检查这一点,我正在查看正在更新的列表项的内容类型,它是正确的

properties.ListItem.ContentType.Name    "Experiment Document Set"

So basically I have a workfow associated with the content type "Experiment Document Set".所以基本上我有一个与内容类型“实验文档集”相关联的工作流。 When I try to start a workflow from an event receiver in "Experiment Document Set", I get an error saying the content type "Experiment Document Set" does not exist in the list which doesn't make sense.当我尝试从“实验文档集”中的事件接收器启动工作流时,我收到一条错误消息,指出列表中不存在没有意义的内容类型“实验文档集”。

确保 assoc.Enabled = true。

Probably too late to be helpful, but I just learned that you can't use String.Empty (or null ) in the StartWorkflow method.可能为时已晚,无法提供帮助,但我刚刚了解到您不能在StartWorkflow方法中使用String.Empty (或null )。

From http://www.tonytestasworld.com/post/Howto-Start-a-Sharepoint-Workflow-Programmatically.aspx , it looks like assoc.AssociationData would work for a simple workflow without any configuration parameters.http://www.tonytestasworld.com/post/Howto-Start-a-Sharepoint-Workflow-Programmatically.aspx看来, assoc.AssociationData可以用于没有任何配置参数的简单工作流。

I can't test this (yet), because I'm stuck a step earlier, possibly similar to the issue you mentioned in your first two code examples.我(还)无法对此进行测试,因为我提前了一步,可能类似于您在前两个代码示例中提到的问题。

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

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