Sharepoint 2010事件接收器和工作流程无法启动

时间:2013-07-02 21:28:22

标签: sharepoint sharepoint-workflow event-receiver

我创建了一个应该触发SharePoint设计器工作流的事件接收器,但这种情况从未发生过。对于guid和工作流关联,这部分代码永远不会评估为true:if(association.BaseId == workflowGuid)。我有点难过,不太确定为什么它不起作用。任何见解将不胜感激......我的代码如下。基本上当一个项目被添加到我的列表中时,它应该触发我的Sharepoint设计器工作流程,但这种情况从未发生过,我可以手动启动工作流程。

public override void ItemAdded(SPItemEventProperties properties)
{
       base.ItemAdded(properties);
       startWF(properties);
}

private void startWF(SPItemEventProperties properties)
{
       try
       {
           //bool startWF = false;
           string strWorkflowID = "{c66ff94f-ba7c-4495-82fe-e73cdd18bad9}";
           //string statusVal = properties.AfterProperties["eRequest Division"].ToString();
           SPListItem li = properties.ListItem;
           //using (SPWeb web = li.Web)
           using (SPWeb web = properties.OpenWeb())
           {
               using (SPSite site = web.Site)
               {
                   SPWorkflowManager mgr = site.WorkflowManager;
                   SPList parentList = li.ParentList;
                   //SPList list = web.Lists["Charitable and Political"];
                   SPWorkflowAssociationCollection associationCollection = parentList.WorkflowAssociations;
                   LookUpAndStart(li, mgr, associationCollection, "{c66ff94f-ba7c-4495-82fe-e73cdd18bad9}");
               }

           }

       }
       catch (Exception ex)
       {

       }
   }

private static void LookUpAndStart(SPListItem listItem, SPWorkflowManager mgr, SPWorkflowAssociationCollection associationCollection, string workflowID)
{

    foreach (SPWorkflowAssociation association in associationCollection)
    {
           Guid workflowGuid = new Guid(workflowID);
           //if (association.Name.ToLower().Equals(workflowGuid))
          //if (association.BaseId == workflowGuid)
           //if (association.BaseId.ToString("B").Equals(workflowGuid))
           if (association.BaseId == workflowGuid)
           {
               string data = association.AssociationData;
               SPWorkflow wf = mgr.StartWorkflow(listItem, association, data, true);
               break;
           }
       }
    }
  }
}

1 个答案:

答案 0 :(得分:0)

就我而言,以下是问题所在。

如果满足以下条件,则声明性工作流将不会自动启动:

  1. Windows SharePoint Services Web应用程序在用户的域帐户下运行。
  2. 用户使用此域帐户登录。
  3. 该站点将用户名显示为“系统帐户”。