Send a notification email after a work item is newly created
I want to send an email only when a work item is completely created (i.e. all preconditions and follow-up actions have passed successfully).
Is there a way (for example, to create a new participant) to be sure that I can safely send the email and to be sure that there are no other follow-up actions which may prevent the work item from being saved?
What is the action id if it exists?
I was thinking of several alternatives:
1) create a participant and check if there is no oldState of the work item. Then create a notification email
The drawback here is that I think I am not sure that there could be other follow-up actions which happen after mine and prevent the saving of the work item after mine.
2) Create a participant which adds the users to the subscribers list when the work item is newly created.
The issue here is that I want to send a notification email only during the creation of the work item, but not during each update.
3) Create an asynchronous task, which checks if the work item is created and no emails have been sent.
The issue here is that I am not sure if an email has already been created.
Thanks!
Accepted answer
You can create a followup action. It is pretty easy to detect that a work item is new. The extensions Workshop has some code for it already.
- Is doable
- Is an ugly duckling solution that requires 1 and drives users nuts being subscribed to crap they don't want.
-
I don't know how to detect the newly create item. https://rsjazz.wordpress.com/2015/10/16/due-date-notifier-an-asynchronous-task-example/ is an example for other stuff, it also has the server code for e-maling if you want to use it in 1 or 3.
Comments
One other answer
One option you could consider is looking at the "AdditionalSaveParameter" value of the saveWorkItem3 operation in the follow-up actions. If each follow-up action passes along its own unique id but preserves the ones that it received, then your final follow-up action could review all those save parameters and only send the e-mail if all of the expected parameters are present. If all parameters are present, that would indicate that all follow-up actions have fired.