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
In case option number 1 is selected and I create a participant and send an email in case a new work item is created, how can I be sure that I will not send an email and them another participant fails (executed after mine) which can prevent from saving the work item?
In other words, is there any order of advisor and participant execution? Can I be sure that if I send an email in my participant the work item will surely be saved?
The order is the order the behavior is configured for the operation and role from top to bottom.
Just for confirmation, the only way to ensure that I send an email to a user right after a work item has just been created is to put my participant in the end of all follow-up actions list?
I am sure there are other mechanisms that can be used, but I don't have any particular information about them. I can only answer what I know.
Possible paths to explore would be
+ Asynchronous tasks https://rsjazz.wordpress.com/2015/10/16/due-date-notifier-an-asynchronous-task-example/
+ Events
But I can't provide you details and if these paths can definitely be used.
Thanks a lot!
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.