Customize your AX Workflow Email Templates

12 12 2012

A number of our clients have made requests of us to provide more meaningful information available on the Email notifications that are sent to the workflow work-item assignees. The typical information that they would like to see is line item information for workflow relating to Purchase Requisitions etc.

The easiest way is to modify the various task and step instructions in your workflow configuration. You can select tags relating to the lines such as %Purchase Requisition.Purchase requisition lines.ItemId% etc. These instructions can be displayed in your workflow email notification by including the %message% tag in your email template.

Screen Shot 2012-12-12 at 10.11.38 AM

However using this approach is not very flexible or visually appealing as each tag is replaced by a comma separated list of the values from the various lines. Most of our clients have required a more tabular format for the lines. My approach to solving their issue is by using a code based solution that I will describe below.

I’d like to say at the outset that the disadvantages to this approach is that it doesn’t easily allow for multi-language, its fairly rigid, and it is a more hard-coded solution making it not very flexible.

Step 1. Create a method ‘wfDescription’.

Create a ‘wfDescription’ method on each Workflow Document table that you are using. This method should return an block of html (or plain text) with the content that you would like to display for the given document type. E.G. For a purchase requisition add the following method to the PurchReqTable table.

str wfDescription() 
 PurchReqLine line;
 str ret="";
 ret = ret + strfmt("<strong>Motivation: </strong>%1<br/>", this.businessJustification()); ret = ret + "<strong>Lines:</strong><br/>";
 while select line where line.PurchReqId==this.PurchReqId
   ret = ret + strfmt("%1. %2 <span style='color: #009966'> (%3 @ %4 %5) - %6</span><br/>",num2str(line.LineNum,0,0,1,3), line.itemName(), line.PurchQty, line.CurrencyCode, line.PurchPrice, line.LedgerAccount);
 return ret;

Step 2: Add a description tag to your email template

Open up your email template and place a %documentdescription% tag in the place where you would like the text/html block from Step 1 to appear in your emails.

Step 3: Enable the %documentdescription% tage

This is the key step in the whole process. To enable workflow to replace the new %documentdescription% tag created in Step2 with the contents from the method in Step 1. To do this we will be customizing the ‘EventNotificationWorkflow’ class:

  • Open the ‘EventNotificationWorkflow’ class.
  • Edit the sendMail method.
  • Add the line ‘this.addCustomMergeValues();’ after the line ‘this.addBaseMergeValues();’
  • Create a new method named ‘private void addCustomMergeValues()’ to the ‘EventNotificationWorkflow’ class.
    This method will determine whether the workflow document has the ‘wfDescription’ method and will replace the tag with what the method returns.
private void addCustomMergeValues2()
  SysDictTable dictTable; 
  str description;
  dictTable = new SysDictTable(tablenum(PurchReqTable));

  if (dictTable.isMethodActual('wfDescription'))
     description = dictTable.callObject('wfDescription',record);
    description = "";
  mergeValues.insert("documentdescription", description);

The final step is to prevent the html from your return method from being escaped. To do so:

  • Open up the SysEmailTable (Table) in the AOT
  • edit the HTMLEncodeParameters method
  • Add a conditional statement before the line ‘encodedMap.insert(mapEnum.currentKey(), SysEmailTable::htmlEncode(mapEnum.currentValue()));’ so that your new tag %documentdescription% is not html encoded.
if (mapEnum.currentKey() == 'documentdescription')
    encodedMap.insert(mapEnum.currentKey(), mapEnum.currentValue());
    encodedMap.insert(mapEnum.currentKey(), SysEmailTable::htmlEncode(mapEnum.currentValue()));

If all goes well you should now receive more detailed information in your email notification.
Let me know if you have any better ways of accomplishing this or comments on my solution.

Happy daxing.


Setting up notifications on Approvals

11 04 2012

Yesterday i received a query from a client on how to setup a notification so that the person who submits a document to workflow gets notified once it had been approved. I quickly recorded the following screencast. I recommend watching it in high quality otherwise everything is a bit small.

Why is my yellow workflow bar not displaying

20 09 2010

My most common complaint regarding workflow from users or developers is “MY YELLOW WORKFLOW BAR IS NOT DISPLAYING”. So here is my mental checklist of probable causes to help resolve this common issue (this is a list in progress as there always seems to be a a new reason for why this is happening, so if you have found additional reasons please post them in the comments below)

1) Check that your canSubmitToWorkflow method on your form is returning true, if you are trying to submit to workflow. It may be that the rules that are setup are not allowing the record to be submitted. e.g. no lines have been added yet for the Purchase Req.
2) If the user is supposed to be approving the record, check that the record is still assigned to him (Basic -> Workflow History). This sounds silly but users often see the email notification in outlook and try and approve their again when it may already have been approved or escalated.
3) Check that a workflow configuration exists and is marked as active for the record type in question
4) Ensure that your form is workflow enabled.
5) Ensure that the correct data source is marked as the workflow data source for your form.

If you are still struggling, here are some less common reasons
1) No submit menuitem has been defined for workflow template selected as the active workflow configuration. I’ve experienced this when I’ve got 2 workflow configurations for the same record type with the first configuration kicking off the second one as a sub-workflow. In this case the second workflow does not require a submit menuitem. However Dynamics AX marks both as default and may pick-up the one without the submit button as the default and subsequently not anything because no submit button is available.

Happy Daxing.

Adding custom fields to workflow emails

26 08 2010

Hi all.
For today we are going to be taking a quick look at one of the ways in which you can add custom tags to your workflow emails. For example by default one does not have the option to display the name of the user whom the work item has been assigned to, but you may want to start out your email saying “Dear %assignedToName%” and have AX automatically populate this for you. One of the simplest ways to accomplish this is by customizing the EventNotificationWorkflow class. (Note: This is a framework class so be careful when upgrading).

Step 1 – Add a new method such as “void addCustomMergeValues()”
Step 2 – Add as the new tags that you would like to access by using the following format mergeValues.insert(“field1″,”myValue”); – in this case putting the tag %field1% in your email template, you final emails that are send out would be populated with “myValue”.
Step 3 – Call you custom method from the “sendMail” method of EventNotificationWorkflow. The best place to put this call would be directly below “this.addBaseMergeValues();” (line 25).

After doing this you should be able to freely use all your new tags in you email templates. Here is my example of how to insert the notification owner’s name into your template.

void addCustomMergeValues()
UserInfo user;
select user where user.Id==inbox.UserId;

Note: You can also add custom values from the record that the notification is for, by making use of global variable “record” available in EventNotification e.g.

if (record.TableId == purchTable.TableId)
} else if (record.TableId = purchReq.TableId)

Happy Daxing

%d bloggers like this: