I’ve been asked to confirm the e-mails that are sent from Dynamics AX workflows.

As usual I’m working in the Demo Hyper-V image (AX 2012 R3 CU9), and that image relies on another Hyper-V image to run Exchange to send emails, so I’ve downloaded the SMPT4Dev tool, as described in this blog post: https://blogs.msdn.microsoft.com/axsupport/2015/08/27/isolate-issues-related-to-e-mail-not-sending-from-dynamics-ax-2012-using-the-smtp4dev-tool/. But if your Dynamics AX test environment is sending emails, then just skip this step.

Next I check my Workflow parameters. Organisation administration > Setup > Workflows > Workflow parameters. You’ll see that there is only one workflow parameter, the e-mail template that is used to send notifications.:

You can also see that e-mail templates are setup at Organisation administration > Setup > E-mail templates. There are some good examples in the demo data:

However, there’s a nice little trap for young players on the E-mail templates form. E-mail templates can be flagged as a ‘system e-mail’:

System e-mail templates are organisation-wide and therefore are setup once, and apply to all companies; normal e-mail templates are setup per company

Click on the ‘E-mail message’ button and you’ll see something like:

So as you can see the message can be formatted, and can include %placeholders% that are replaced by data when the workflow notification email is sent out. A full list of the placeholders can be found on Technet at: https://technet.microsoft.com/en-us/library/aa834423.aspx, and it is as follows, but workflow e-mail don’t use all of these placeholders:

HTML merge data element Information that is displayed in the email message
%subject% The subject that is defined by the owner of the alert rule.
%message% The message that is written by the owner of the alert rule.
%event% The event that occurred.
%occurred% The date on which the event occurred.
%for% The record in which the event was observed.
%data% Detailed information.
%company% The company at which the event occurred.

You can also include these placeholders in the ‘Subject’ line of the E-mail template as shown above.

If your users are set to use different languages, remember that you will need to create a different language version of each e-mail template.

Now we’ll see in a little while that we can specify a different workflow template on each workflow – and there we use ‘system e-mails’, but back on our Workflow parameters we use one of the normal e-mail parameters, so I’ve set my parameter to:

Now let’s setup a simple Purchase requisition approval workflow. Procurement and sourcing > Setup > Procurement and sourcing workflows, and I click on the ‘New’ button and select a Purchase requisition review workflow and click Create workflow:

A blank workflow opens with a number of errors defined:

Incidentally, you can double click on an error message to be taken to the source of the error, where you can correct it.

Because I’m only interested in Notifications today, I’m going to setup a simple workflow that will run for Purchase requisitions created by the ‘admin’ user, and they’ll be approved by my alter ego Tim Ball. Note that while I’m setting up the workflow and approval steps I must enter instructions – these can be part of your email template above, and the instructions themselves can include placeholder information like the purchase requisition vendor and total amount.

So my workflow is ‘simple as’ with a single approve workflow step:

When you’re working in a workflow, be aware of your selection, the ‘focus of control’. Notice that in the screenshot above the whole workflow is highlighted, so the ‘Notifications’ button opens with setup that refers to the workflow:

When you enable a notification you must enter text (with placeholders) and you should translate the text for each of your users’ languages. You also get to specify the recipient:

Also, back on the Basic setting tab [for the workflow] you specify an e-mail template, and as mentioned before, here we’re selecting from ‘system’ e-mails:

Now I’ll select the Purchase requisition approval step, and this time the Notifications are specific to this step:

As before – when you enable a notification you enter text, and define one or more recipients:

Again insert placeholders, and translate as required.

I’ve saved and activated my workflow.

This caught me out first time through – but notice that none of those options for sending notifications refer to the crucial step of letting you know that a purchase requisition has been assigned to you for approval. That notification is automatic – but it’s not automatically sent to you as an email. Look at the user options. File > Tools > Options or System administration > Common > Users > Users > Users > Setup > Options.

On the Notifications tab tick the ‘Send notifications in email’ checkbox:

I’ve mentioned the user’s language a few times, that’s set here on the Options, and Notifications use this e-mail address (not the contact e-mail attached to the HR Worker which is linked to this user id via the User relations):

One final check – that I have a workflow message processing batch job running:

And I can create and Submit my Purchase requisition:

Now Workflow emails use the System Administration E-mail processing queue to send, so after the workflow has started I can see a couple of e-mails queued ready to send at System administration > Periodic > E-mail processing > E-mail sending status:

And these e-mails are sent by the batch job setup at System administration > Periodic > E-mail processing > Batch:

The outgoing email queue is organisation-wide, (all companies) so you only need one E-mail distributor batch job running, it processes e-mails for all companies.

Once the job has run I can see the e-mail in my SMTP4Dev window:

Obviously I need to correct my setup – the %event% placeholder isn’t used by workflow e-mails, only alerts.

Next I’ll log on as Tim Ball and approve this purchase requisition, and again after the workflow batch job has processed the requisition another couple of e-mails are queued ready to send:

So we’ve seen that we can have e-mail notifications whenever a workflow action takes place – but that isn’t really the whole story. Ideally you’d also get notifications when an action hasn’t taken place: specifically, I’m thinking of purchase requisition approvals that have been waiting for too long.

Probably the best option is to set an ‘Escalation’ action on the workflow approval step:

And, as you can see above, notifications can be sent when a workflow work item is escalated.

Alternatively, you could setup a Cue or Alerts to monitor overdue purchase requisition approvals. For instance:

And of course, this alert can be sent as an e-mail as well.