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;
mergeValues.insert('assignedToName',user.name);
}

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)
{
    purchTable.data(record);
   mergeValues.insert("docKey",purchTable.PurchId)
} else if (record.TableId = purchReq.TableId)
{ 
   purchReq.data(record);
   mergeValues.insert("docKey",purchReq.PurchReqId");
}

Happy Daxing

Advertisements

Actions

Information

4 responses

7 07 2011
Workflow Walkthrough – Infrastructure | Sasidhar Dhruva

[…] can use a number of ‘tags’ with in your template (and email subject) that will allow you to open and link to the correct […]

9 03 2012
Tay

Excellent blog,

I am a new comer to the Workflow templates..Is there any chance your could provide screen shots of where the code should sit in the class framework,

I am having troubles know where

18 05 2012
Anna

Excellent post. Thanks so much :)

3 04 2015
BB

Hi,

Can you tell me if custom merge values can also be created for alert emails rather than workflow? I’m trying to show more data in my email messages by creating my own merge values in the base EventNotification class following your example but have not had any luck. Any help would be appreciated.

Thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: