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.
Asked
Active
Viewed 1,375 times
1 Answers
0
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
).

Geeky Guy
- 9,229
- 4
- 42
- 62
-
Have you got a source for the statement, creating or editing a list item using the API will not trigger workflows ? I've seen other posts that say they do but require, site.WorkflowManager.Dispose(). – BinaryJam Sep 10 '14 at 08:01
-
Empirical evidence. Try it yourself. – Geeky Guy Sep 10 '14 at 10:46
-
Thanks for that. I think what you meant to say was http://support.microsoft.com/kb/947284 http://blogs.technet.com/b/victorbutuza/archive/2009/03/14/workflows-do-not-start.aspx You're right, other chap was well wrong. :-) – BinaryJam Sep 11 '14 at 11:42
-
I work mostly with SharePoint Online, where you don't have access to those settings. I was speaking mostly from experience, but it is good to know that with an in-premises installation workflows can be triggered normally without the need for extra coding. Thanks for that :) – Geeky Guy Sep 11 '14 at 12:46