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);
  }
  else
  {
    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());
else 
    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.

Advertisements




“Stopped (error) X++ exception: the condition could not be evaluated” in Microsoft Dynamics AX 2012

31 10 2012

Just found a Knowledge base article that deals with the issue: “Stopped (error) X++ exception: the condition could not be evaluated” error message when you try to view workflow details in Microsoft Dynamics AX 2012

You can find the issue here: https://mbs2.microsoft.com/Knowledgebase/kbdisplay.aspx?scid=kb,EN-US,2657380

Although I haven’t experienced this issue myself I’m reposting it for anyone else who might be experiencing the problem.





Cumulative Rollup 3

17 07 2012

For all of those out there who don’t yet know this, CU3 for Dynamics AX 2012 has been released with a number of hotfixes that fix various workflow issues. The majority of the issues seem to center around specific workflow types in CRM, AP Invoicing, AP and Purchase Requisitions.

However there are some fixes with the framework including a fix to an issue that forced the workflow execution account to be in en-us language and a fix for workflows submitted in companies that are not the default for the workflow batch job.

You can access the Update and knowledge base article here: https://mbs2.microsoft.com/Knowledgebase/KBDisplay.aspx?scid=kb;EN-US;2709934 (Partnersource login required)





Stopped (error): Failed to find workflow instance. Failed to find workflow instance.

4 05 2012

We recently recently came across an issue at a client site where workflows instances would be completed but the status would be “Stopped (error)” with error messages saying “Failed to find workflow instance. Failed to find workflow instance. Failed to find workflow instance. Failed to find workflow instance” after investigating the issue for quite a while and not finding a solution I eventually found a post at “Peng’s Dynamics AX” Blog where he listed a hotfix that Microsoft released to resolve this bug. The knowledge base article for KB2398999 and download link can be found at: http://support.microsoft.com/hotfix/KBHotfix.aspx?kbnum=2398999&kbln=en-us&sd=mbs#step2

Thanks to Peng for reporting this issue to Microsoft and following up with them for a year! You can view the original blog post here.





Resource Page for Known issues in AX2009 Workflow

3 05 2012

Recently came across this blog page with a list of workflow resources including hotfixes videos etc…

https://community.dynamics.com/product/ax/axtechnical/b/axresources/archive/2012/02/13/resource-page-for-workflow-in-microsoft-dynamics-ax-2009.aspx





Rollup 7 Released

6 05 2011

Microsoft has release rollup 7 for Microsoft Dynamics AX 2009 service pack 1. Of course the most interesting part to me are the two workflow bugs that it resolves.

1. One can start multiple workflow instances for the same record
2. Records in the workflow history form are displayed very slowly

We’ve come across both of these issues and are really glad that official fixes have now been released.

Happy Daxing





Rollup 6 Workflow fixes

3 12 2010

With the release of Hotfix Rollup 6 for Dynamics AX, it seems like a number of issues relating to workflow have been resolved. Checkout the full list over at the Knowledge Base. The one in particular that I’m quite interested in relates to last weeks post on security issues for workflow.

The work-items that were being created when that issue occured remained in status pending and were not removed from the processing queue. The hotfix (KB971260) makes a change to the SysWorkflowEventDispatcher class to catch the error and stop the workitem from processing. It doesn’t seem like the correct security is being applied as yet.

 








%d bloggers like this: