Customize Your AX Workflow Email Templates

download Customize Your AX Workflow Email Templates

of 3

Transcript of Customize Your AX Workflow Email Templates

  • 8/13/2019 Customize Your AX Workflow Email Templates

    1/3

    Customize your AX WorkflowEmail Templates12122012A 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.

    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.

    Id like to say at the outset that the disadvantages to this approach is that it doesnt 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 wfDescriptionCreate 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("Motivation: %1
    ", this.businessJustification()); ret = ret +

    "Lines:
    ";

    while select line where line.PurchReqId==this.PurchReqId

    {

    http://workflowax.wordpress.com/2012/12/12/customize-your-ax-workflow-email-templates/screen-shot-2012-12-12-at-10-11-38-am/
  • 8/13/2019 Customize Your AX Workflow Email Templates

    2/3

    ret = ret + strfmt("%1. %2 (%3 @ %4 %5) -

    %6
    ",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 templateOpen 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 tageThis 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

  • 8/13/2019 Customize Your AX Workflow Email Templates

    3/3

    {

    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.