Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

A SharePoint workflow can be associated with a list, and configured to 'start when a new item is created', 'when an item is changed' or 'manually started by an authenticated user'.

This is my screenshot: http://i.stack.imgur.com/8SIer.png

I need a way of detecting which of these caused the workflow to start in each case. I'm sure there must be some variable which holds which of the above triggered the start of the worklow...

NOTE: I'm developing a SP2010 workflow in C# using Visual Studio.

share|improve this question

2 Answers 2

A somewhat reliable method would be to check for the changed/created date of the list item, at the start of the workflow, and compare it to the start date of the current workflow instance.

If you need it to be 100% failproof, I guess you could create two more workflows, set one to execute on item change, and another on item creation, do what processing you need to do in each case, and then set them to invoke the original one?

share|improve this answer

I have found the best method to do this is to use a field with a default value. If the value is XYZ, then it's new, do your thing, and then set the field to ABC. It's crude but reliable.

HTH

share|improve this answer
    
Thanks for the reply. It's not the detecting of what's changed that's the problem, I have a handler for that (using versions). The problem is detecting what caused the workflow to start each time it runs. i.e; one time it might start because someone invoked it, another time could be a new item, another time a change to an item.... that's what I need to detect, as they're to be handled differently. –  Tom Dec 4 '12 at 22:06
    
Oh, I see, I missed the manually triggered part. I'm not sure how to do this, doing some searching appears that this is a common question, with no good answers. Good luck! –  David Lozzi Dec 5 '12 at 14:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.