2011-01-31 2 views
1

J'ai un flux de travail personnalisé que je commence par le code. Le code suivant que j'utilise pour démarrer un workflow.Problème au démarrage du workflow Sharepoint

DeleteWorkflowTasks(properties.ListItem.ID); 
         Thread thread = new Thread(delegate() { StartApprovalWorkflow(); }); 
         thread.Start(); 

private void StartApprovalWorkflow() 
     { 
      try 
      { 
       SPSecurity.RunWithElevatedPrivileges(delegate() 
        { 
         try 
         { 
          using (SPSite elevatedSite = new SPSite(siteID)) 
          { 
           using (SPWeb elevatedWeb = elevatedSite.OpenWeb(webID)) 
           { 

            SPList calendarList = elevatedWeb.Lists[listID]; 
SPWorkflowAssociation workflowAssociation = calendarList.WorkflowAssociations.GetAssociationByName(currentWorkflowName, System.Threading.Thread.CurrentThread.CurrentCulture); 
            elevatedSite.WorkflowManager.StartWorkflow(itemBeforeUpdate, workflowAssociation, workflowAssociation.AssociationData); 
           } 
          } 
         } 
         catch (SPException ex) 
         { 
                } 
         catch (Exception ex) 
         { 
                } 
        }); 
      } 
      catch (SPException ex) 
      { 

      } 
      catch (Exception ex) 
      { 
      } 
     } 

Ce code est attaché avec ItemUpdated eventhandler code.Whenever mettre à jour un élément, il annule le flux de travail qui est déjà attaché et crée un nouveau flux de travail pour le même item.Though il fonctionne très bien mais parfois le flux de travail est ne démarre pas mais le workflow précédent est annulé. La trace de pile que j'obtiens est la suivante.

Object reference not set to an instance of an object. at Microsoft.SharePoint.Library.SPRequestInternalClass.OpenWeb(String bstrUrl, String& pbstrServerRelativeUrl, String& pbstrTitle, String& pbstrDescription, Guid& pguidID, String& pbstrRequestAccessEmail, UInt32& pwebVersion, Guid& pguidScopeId, UInt32& pnAuthorID, UInt32& pnLanguage, UInt32& pnLocale, UInt16& pnTimeZone, Boolean& bTime24, Int16& pnCollation, UInt32& pnCollationLCID, Int16& pnCalendarType, Int16& pnAdjustHijriDays, Int16& pnAltCalendarType, Boolean& pbShowWeeks, Int16& pnFirstWeekOfYear, UInt32& pnFirstDayOfWeek, Int16& pnWorkDays, Int16& pnWorkDayStartHour, Int16& pnWorkDayEndHour, Int16& pnMeetingCount, Int32& plFlags, Boolean& bConnectedToPortal, String& pbstrPortalUrl, String& pbstrPortalName, Int32& plWebTemplateId, Int16& pnProvisionConfig, String& pbstrDefaultTheme, String& pbstrDefaultThemeCSSUrl, String& pbstrAlternateCSSUrl, String& pbstrCustomizedCssFileList, String& pbstrCustomJSUrl, String& pbstrAlternateHeaderUrl, String& pbstrMasterUrl, String& pbstrCustomMasterUrl, String& pbstrSiteLogoUrl, String& pbstrSiteLogoDescription, Object& pvarUser, Boolean& pvarIsAuditor, UInt64& ppermMask, Boolean& bUserIsSiteAdmin, Boolean& bHasUniquePerm, Guid& pguidUserInfoListID, Guid& pguidUniqueNavParent, Int32& plSiteFlags, DateTime& pdtLastContentChange, DateTime& pdtLastSecurityChange, String& pbstrWelcomePage) 
    at Microsoft.SharePoint.Library.SPRequest.OpenWeb(String bstrUrl, String& pbstrServerRelativeUrl, String& pbstrTitle, String& pbstrDescription, Guid& pguidID, String& pbstrRequestAccessEmail, UInt32& pwebVersion, Guid& pguidScopeId, UInt32& pnAuthorID, UInt32& pnLanguage, UInt32& pnLocale, UInt16& pnTimeZone, Boolean& bTime24, Int16& pnCollation, UInt32& pnCollationLCID, Int16& pnCalendarType, Int16& pnAdjustHijriDays, Int16& pnAltCalendarType, Boolean& pbShowWeeks, Int16& pnFirstWeekOfYear, UInt32& pnFirstDayOfWeek, Int16& pnWorkDays, Int16& pnWorkDayStartHour, Int16& pnWorkDayEndHour, Int16& pnMeetingCount, Int32& plFlags, Boolean& bConnectedToPortal, String& pbstrPortalUrl, String& pbstrPortalName, Int32& plWebTemplateId, Int16& pnProvisionConfig, String& pbstrDefaultTheme, String& pbstrDefaultThemeCSSUrl, String& pbstrAlternateCSSUrl, String& pbstrCustomizedCssFileList, String& pbstrCustomJSUrl, String& pbstrAlternateHeaderUrl, String& pbstrMasterUrl, String& pbstrCustomMasterUrl, String& pbstrSiteLogoUrl, String& pbstrSiteLogoDescription, Object& pvarUser, Boolean& pvarIsAuditor, UInt64& ppermMask, Boolean& bUserIsSiteAdmin, Boolean& bHasUniquePerm, Guid& pguidUserInfoListID, Guid& pguidUniqueNavParent, Int32& plSiteFlags, DateTime& pdtLastContentChange, DateTime& pdtLastSecurityChange, String& pbstrWelcomePage) 
    at Microsoft.SharePoint.SPWeb.InitWeb() 
    at Microsoft.SharePoint.SPWeb.get_UserInfoListId() 
    at Microsoft.SharePoint.SPListItem.CalculateEffectivePermMask(SPBasePermissions permIn) 
    at Microsoft.SharePoint.SPListItem.get_EffectiveBasePermissions() 
    at Microsoft.SharePoint.SPListItem.DoesUserHavePermissions(SPBasePermissions permissionMask) 
    at Microsoft.SharePoint.Workflow.SPWorkflowManager.StartWorkflow(SPListItem item, SPWorkflowAssociation association, String eventData, Boolean isAutoStart) 
    at Microsoft.SharePoint.Workflow.SPWorkflowManager.StartWorkflow(SPListItem item, SPWorkflowAssociation association, String eventData) 

Appréciez toute aide à ce sujet.

Répondre

2

objets complexes vous faites référence à l'intérieur d'un contexte élevé MUST être créé dans ce contexte

donc ceci:

elevatedSite.WorkflowManager.StartWorkflow(itemBeforeUpdate, ... 

doit être changé à quelque chose comme ceci:

elevatedItem = calendarList.GetItemById(itemBeforeUpdate.Id) 
elevatedSite.WorkflowManager.StartWorkflow(elevatedItem, ... 
Questions connexes