Invoke SharePoint Workflow after EventReceiver

点点圈 提交于 2019-12-08 09:19:38

问题


i got a question regarding sharepoint workflows and event receivers. i got an event receiver that is setting metadata on an element. after that, i use a workflow to copy item metadata to a list. unfortunately the workflow does not copy the metadata set by the event receiver. i think because it is executed before the event receiver. is there a possibility to change the order, so that the workflow will execute after the event receiver? the receiver ist bound to the ItemAdded and ItemUpdated Events i a syncrounous manner.

Thank you for your help! Patrick


回答1:


You can use SPWorkFlowAssociation to run workflow that associate with List or Content Type . Example ( run workflow after adding item)

public override void ItemAdded(SPItemEventProperties properties)  
{  

    SPList parentList = properties.ListItem.ParentList;  
    SPWorkflowAssociation associationTemplate =         
      parentList.WorkflowAssociations.GetAssociationByName("Your Workflow Name",   
      new CultureInfo  
        (Convert.ToInt32(parentList.ParentWeb.RegionalSettings.LocaleId)));  
    SPSite siteCollection = properties.ListItem.ParentList.ParentWeb.Site;  
      siteCollection.WorkflowManager.StartWorkflow(properties.ListItem,  
      associationTemplate, String.Empty);  

}  

More information about SPWorkflowAssociation Check the below link

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.workflow.spworkflowassociation.aspx




回答2:


SPListItem:

The "Synchronous" events (-ing ending like ItemAdd*ing*), are always executed before the workflow.

The "Asynchronous" events (-ed ending like ItemAdd*ed*), are always executed after the execution of the workflow.

So, you have to set the "Synchronization" property of the Elements.xml file equal to "Synchronous" and the workflow will always be executed after the event receiver.

ATTENTION: Events Added and Updated run asynchronously by default, so you have to do the change in the Elements.xml .



来源:https://stackoverflow.com/questions/4483446/invoke-sharepoint-workflow-after-eventreceiver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!