1

我创建了一个应该触发 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;
           }
       }
    }
  }
}
4

1 回答 1

0

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

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

  1. Windows SharePoint Services Web 应用程序在用户的域帐户下运行。
  2. 用户使用此域帐户登录。
  3. 该站点将用户名显示为系统帐户。
于 2019-10-15T14:17:48.493 回答