Email not sent on followup action during work item create
I have a custom followup action that upon a new work item create, will automatically add team area members as subscribers based on the Category association to a team area. All of that works fine, however, we have discovered that the initial email notification of a [new] work item is not sent. The only email notification that is sent is the one that shows the addition of subscribers.
The code is making changes to the work item copy (adding members to the ISubscriptions) and then doing a typical save on the work item copy via:
workItemServer.saveWorkItem2(workItemWorkingCopy, null, null);
We know that an initial "virtual" save has already been done, since this is a followup action, thus we are adding to the work item and doing the 2nd virtual save. Once all followup actions have been run to completion, the complete (new) work item is committed to the database. Notifications for emailing appear to only be inspecting the last "change".
In our case, it had this effect: The owner of the work item was not notified (no new email) and did not receive the email on the subscription additions because by default a person's email configurations are set to not receive those. But other team members did receive the subscription added email. As a further test, I changed my email notifications to basically give me everything. I created a new work item. The only email I received was of the subscriber additions... no [new] work item creation email was received.
Has anyone else run into this? This scenario would apply to any followup action that is making a change to the work item while it is being created. Should this be done as a precondition perhaps (however, making changes to the work item in preconditions is discouraged)? Is there a preferred technique for this type of followup action?
One answer
Emails sent are also based on the configuration of the user. Make sure they have setup e-mail notification the way you expect it to be.
Be aware, that the follow up action performs an additional save. The initial save to create the work item will not have any subscribers set and hence the creation will not be sent to anyone other than the creator. The same holds true for any other save. The follow up action has no impact on that but would potentially create another save. Also note that you need to protect the follow up action from being called due to the second save you do. You probably have, otherwise we would not communicate here.
EWM was initially designed to reduce e-mail mess and provides mechanisms such as feeds etc. We failed. Developers inboxes are still spammed.
If you want different behavior for mail notifications, you might want to also check https://rsjazz.wordpress.com/2015/10/16/due-date-notifier-an-asynchronous-task-example/
Comments
Thank you for your reply, Ralph. Your statement "The initial save to create the work item will not have any subscribers set and hence the creation will not be sent to anyone other than the creator." is the very thing I'm looking to happen, but is not. I've verified the user's email notification settings and as an owner of a new work item, they should get a [new] work item email, but they do not. So in my test, I turned on all my email notifications (all options checked). When I created a new work item with my followup action running, I (as creator and modifier) did not get that initial [new] work item email. I only got the subscriber update email. Where is the [new] work item email?
The code does do a check on the operation data to only run if getOldState() is null (meaning it's recognizing this is the creation of a new work item).
You presented an interesting idea that if I can't get the [new] email to be sent, I could use the example you sighted to construct and force send an email to (at minimum) the owner.
I don't understand why the initial mail to the creator does not get sent. I would check log files etc.