SharePoint timer job add list items, but does not trigger the associated workflow

假如想象 提交于 2019-12-24 00:53:47

问题


I have a list called "Sessions", The list has a workflow which runs for item creation, modification. The workflow triggers when i add items using a web part as well as manually . I have developed a timer job which runs daily, which adds items to "Sessions" list. When timer job add items to the list, workflow does not trigger.


回答1:


Creating or editing a list item using the API will not trigger workflows. You have to use the SPWorkflowManager class to trigger it yourself. Every instance of SPSite has a property of just that type, which is what you should use.

You could code it like this:

SPSite site = foo; // Actually get your instance of SPSite by whatever is
                   // your favorite way to do so.

site.WorkflowManager.StartWorkflow(
        item,
        association,
        association.AssociationData,
        isAutoStart);

Where item is the SPListItem which you have created/edited, association is the instance of SPWorkflowAssociation that correlates the list to the actual workflow, and isAutoStart is a boolean variable telling the workflow manager whether the workflow trigger should behave as something that was started automatically (in your case, true).



来源:https://stackoverflow.com/questions/17810185/sharepoint-timer-job-add-list-items-but-does-not-trigger-the-associated-workflo

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