1

Я создаю задачу рабочего процесса ListItem в SharePoint 2013. Рабочий процесс прекрасно работает, когда я добавляю элемент списка создается задача, и нет никакой ошибки. Однако, когда я обновляя элемент кода рабочего процесса дает мне эту ошибку:<nativehr> 0x8102009b</nativehr><nativestack></ nativestack> Workflow Sharepoint 2013

<nativehr>0x8102009b</nativehr><nativestack></nativestack> 

StackTrace

at HBLEventReceiverWP.ApprovalWFRecevier.ApprovalWFRecevier.LookupAndStartWorkflow(SPListItem listItem, SPWorkflowManager manager, SPWorkflowAssociationCollection associationCollection, String workflowId) 
    at HBLEventReceiverWP.ApprovalWFRecevier.ApprovalWFRecevier.ItemUpdated(SPItemEventProperties properties) 
    at Microsoft.SharePoint.SPEventManager.RunItemEventReceiver(SPItemEventReceiver receiver, SPUserCodeInfo userCodeInfo, SPItemEventProperties properties, SPEventContext context, String receiverData) 
    at Microsoft.SharePoint.SPEventManager.RunItemEventReceiverHelper(Object receiver, SPUserCodeInfo userCodeInfo, Object properties, SPEventContext context, String receiverData) 
    at Microsoft.SharePoint.SPEventManager.<>c__DisplayClassa`1.<InvokeEventReceiver>b__7() 
    at Microsoft.SharePoint.SPSecurity.RunAsUser(SPUserToken userToken, Boolean bResetContext, WaitCallback code, Object param) 

Это мой код на itemupdated Event.

public class ApprovalWFRecevier : SPItemEventReceiver 
    { 
     /// <summary> 
     /// An item was updated. 
     /// </summary> 
     public override void ItemUpdated(SPItemEventProperties properties) 
     { 
      base.ItemUpdated(properties); 
       // get site collection web 
      using (SPWeb spWeb = properties.OpenWeb()) 
      { 
       // get current site 
       SPSite spSite = spWeb.Site; 
       // 
       spWeb.AllowUnsafeUpdates = true; 
       // check if it is a component list 
       bool isCompLst = CheckIsComponentList(properties.List.ToString()); 
       if (isCompLst == true) 
       { 
        // set the list item 
        SPListItem listItem = properties.ListItem; 

        // check if item is in preview mode 
        if (properties.List.ToString() == "SitePages") 
        { 
         if (Convert.ToBoolean(listItem["Preview"]) == false) 
         { 
          SPWorkflowManager manager = spSite.WorkflowManager; 
          //get item's parent list 
          SPList parentList = listItem.ParentList; 
          //get all workflows that are associated with the list 
          SPWorkflowAssociationCollection associationCollection = parentList.WorkflowAssociations; 
          //lookup and start the worflow 
          LookupAndStartWorkflow(listItem, manager, associationCollection, "Approval"); 
         } 

        } 
        else if (CheckPreviewCol(listItem, properties) == false) 
        { 
         //obtain an instance of SPWorkflowManager 
         //which will be later used to start the workflow 
         SPWorkflowManager manager = spSite.WorkflowManager; 
         //get item's parent list 
         SPList parentList = listItem.ParentList; 
         //get all workflows that are associated with the list 
         SPWorkflowAssociationCollection associationCollection = parentList.WorkflowAssociations; 
         //lookup and start the worflow 
         LookupAndStartWorkflow(listItem, manager, associationCollection, "Approval"); 

        } 
       } 
      } 



     } 

     #region Methods 

     public bool CheckIsComponentList(string listName) 
     { 
      try 
      { 
       bool IsCompLst = false; 

       switch (listName) 
       { 
        case "HeadingComponent": 
         // set component list to true 
         IsCompLst = true; 
         break; 

        case "ParagraphComponent": 
         // set component list to true 
         IsCompLst = true; 
         break; 

        case "FAQComponent": 
         // set component list to true 
         IsCompLst = true; 
         break; 

        case "FAQComponentDetail": 
         // set component list to true 
         IsCompLst = true; 
         break; 

        case "BulletComponent": 
         // set component list to true 
         IsCompLst = true; 
         break; 

        case "BulletComponentDetail": 
         // set component list to true 
         IsCompLst = true; 
         break; 

        case "ButtonsComponent": 
         // set component list to true 
         IsCompLst = true; 
         break; 

        case "TwoImageComponent": 
         // set component list to true 
         IsCompLst = true; 
         break; 

        case "ImageGridComponent": 
         // set component list to true 
         IsCompLst = true; 
         break; 

        case "ImageWithDescriptionComponent": 
         // set component list to true 
         IsCompLst = true; 
         break; 

        case "GreenTextComponent": 
         // set component list to true 
         IsCompLst = true; 
         break; 

        case "TableComponent": 
         // set component list to true 
         IsCompLst = true; 
         break; 

        case "TableComponentRows": 
         // set component list to true 
         IsCompLst = true; 
         break; 

        case "CenterComponent": 
         // set component list to true 
         IsCompLst = true; 
         break; 

        case "CenterComponentDetail": 
         // set component list to true 
         IsCompLst = true; 
         break; 
        case "SitePages": 
         // set component list to true 
         IsCompLst = true; 
         break; 

        default: 
         // set component list to true 
         IsCompLst = false; 
         break; 
       } 
       return IsCompLst; 
      } 
      catch (Exception ex) 
      { 
       throw ex; 
      } 

     } 
     public bool CheckPreviewCol(SPListItem listItem, SPItemEventProperties properties) 
     { 
      try 
      { 
       bool isPreview = true; 

       bool oldValue = listItem["Preview"] != null ? Convert.ToBoolean(listItem["Preview"]) : true; 
       if (oldValue == true) 
       { 
        bool newValue = properties.AfterProperties["Preview"] != null ? Convert.ToBoolean(properties.AfterProperties["Preview"]) : true; 

        if (oldValue != newValue) 
         isPreview = false; 
       } 
       else 
        isPreview = false; 

       return isPreview; 
      } 
      catch (Exception ex) 
      { 
       throw ex; 
      } 

     } 

     private static void LookupAndStartWorkflow(SPListItem listItem, SPWorkflowManager manager, SPWorkflowAssociationCollection associationCollection, string workflowId) 
     { 
      try 
      { 

       //iterate workflow associations and lookup the workflow to be started 
       foreach (SPWorkflowAssociation association in associationCollection) 
       { 
        //if the workflow association matches the workflow we are looking for, 
        //get its association data and start the workflow 
        if (association.Name.ToLower().Equals(workflowId.ToLower())) 
        { 
         //get workflow association data 
         string data = association.AssociationData; 

         //start workflow with privileges 
         SPSecurity.RunWithElevatedPrivileges(delegate() 
         { 
         SPWorkflow wf = manager.StartWorkflow(listItem, association, data, true); 
         }); 
        } 
       } 
      } 
      catch (Exception ex) 
      { 
       throw ex; 
      } 
     } 

     #endregion 

    } 

ответ

0

Эта ошибка может означать, что для этого конкретного элемента уже существует активный рабочий процесс. решение в вашем случае будет проверять, завершен ли рабочий процесс. Это было бы что-то вроде:

if(workflow.IsCompleted) 
{ 
    //you can start it 
    //this is pseudocode do not rely on it 
} 

Для получения дополнительной информации посетите this source.

 Смежные вопросы

  • Нет связанных вопросов^_^