Workflow emails in AX 2012

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.

Purchase order approval in AX 2012

I’m not a great fan of purchase order approval. Actually it’s not purchase order approval that I have a problem with, it’s purchase order re-approval. Mostly I’m working with inventory purchase orders and master planning. So, first off there are a couple of exceptions to using purchase order approval for inventory purchasing: first, if you firm a planned order, the order’s automatically approved; and secondly you can’t use purchase order approval with sub-contract purchase orders. Then with inventory purchasing you’re going to want to update the purchase order – you need to record the vendor’s confirmed delivery date, and you might want to change requested delivery dates.

With purchase order approval workflows active you can’t just edit the purchase order to make changes – notice that the Edit button is inactive. You have to click ‘Request change’ and then make your change and then re-submit for approval


So let’s make a change to the delivery date and submit the purchase order for approval:


After the workflow messages have been process the Actions > View history button shows me that the purchase order is waiting for approval:


But the problem is that master planning is still seeing the original date (and warehouse and quantity) so we’re looking at changes that won’t have any major financial implications, but they’re important to master planning, and we want to apply those changes immediately, without having to wait for the boss to approve the purchase order.

The solution of course is to include an automatic approval setup in your workflow. I don’t really want to get into workflow setup – it deserves a whole series of posts all on its own – suffice to say that there are some useful ‘fields’ that you can use to setup conditions for automatic approval in your workflow. There’s an example in the standard demo data which uses the purchase order delta invoice amount percentage:


You can also use the purchase order delta invoice amount (rather than the percentage) and as you can see above there is also an option to test the purchase order ‘requires purchase order re-approval’.

The ‘requires purchase order re-approval’ is triggered by a policy. Go to Procurement and sourcing > Setup > Policies > Purchasing polices:


We need the policy that’s active for our company:


(If you’re working on policies, keep an eye on this setting – too easy to be updating a policy that doesn’t apply to the company you’re working in).

Then we need to find or create the ‘Re-approval rule for purchase orders’:


Access the details of the policy by double-clicking on the effective version of the Policy rule. Then you define the fields which, if changed, are going to trigger re-approval:


You can view the fields in a simple list or more complex tree view. For this simple example I’m setting this up so that I can change anything on the purchase order except price and quantity.

Now we’re ready to ‘Request change’ on our purchase order, edit the purchase order, and re-submit for approval. Once the workflow has run we can see that the purchase order’s approved and the workflow history shows that the automatic approval was triggered as required:


But if I change the price or quantity, the purchase order requires manual approval:


Job done.