2012. All rights reserved.
CREATING AUTOMATIC EMAIL
CONFIRMATIONS
Dynamics AX | Sales | X++
Automating e-mail communication is a great way to streamline your business processed. One example of doing this would be to have sales order confirmations sent out when they are approved within the ERP system.
You can do this through workflows if you want, but in this example we will show how you can add a small function to Dynamics AX that will automatically send the confirmations through your local SMTP server, without the user having to even touch their e-mail system.
2012. All rights reserved.
Make Sure That
Your SMTP
Parameters Are Set
The first step is to make sure that you have the SMTP server registered and configured correctly within Dynamics AX. To do this go to the System Administration Setup System Email Parameters.
2012. All rights reserved.
Create An E-mail
Template
Rather than hard code the e-mail body, we are going to take advantage of the e-mail templates functionality that is built into Dynamics AX. You can find the e-mail templates in the Organization Setup E-Mail templates form.
2012. All rights reserved.
Create An E-mail
Template
After you open up the form, you will want to create a new template.
2012. All rights reserved.
Create An E-mail
Template
And also create a new e-mail layout.
2012. All rights reserved.
Create An E-mail
Template
When you open up the layout, you can paste in the e-mail body that you want to use.
For the dynamic sections of the e-mail, place tokens surrounded by %.
2012. All rights reserved.
Create An E-mail
Template
After you have done this, you can preview the e-mail.
2012. All rights reserved.
Find Your Form To
Extend
Now we want to start creating a little bit of X++ code. But before we do that we want to find the form that we want to modify. For this example, I want to override the Conformation button on the Sales Order form. To find the form name, I just opened up the Personalization form, and it will give me the real form name.
2012. All rights reserved.
Find Your Form To
Extend
From there, we can open up AOT and can drill down into the ActionPane items and find the Confirm button that we want to override.
2012. All rights reserved.
Create A New
Project
Rather than change the form directly, its better to wrap the code within a project. So we will create a new project.
2012. All rights reserved.
Add Your Form To
The Project
Now we will drag the form design from AOT over to the project.
2012. All rights reserved.
Override The
Original Method
Now we are going to add our own code to the form for the e-mail. To do this, we will override the clicked method on the form.
2012. All rights reserved.
Override The
Original Method
That will open up the X++ code editor for us. Notice that the method already has a super() function that will call down to the lower level code, so here we just need to add our own code either before or after this function.
2012. All rights reserved.
Create Your Email
Event
To start off we will create a couple of variables to load in the Email Template, and also set a default recipient email address.
Also, after the super() function we will perform a sendEmail. This function will create an e-mail and send it through the default SMTP server. This is a little different from the normal method which requires the e-mail to be sent through the users e-mail package.
2012. All rights reserved.
Create Your Email
Event
To make this a little more dynamic, we will find the customer record for the customer that is referenced in the sales order, and then find their e-mail.
2012. All rights reserved.
Create Your Email
Event
Finally rather than just sending out a form letter with no personalization, we will create a mapping variable, and tell the system to replace all of the tokens that we have in the email with the values from the sales order.
2012. All rights reserved.
Configure Your
Customer Contact
Preferences
Now we can test the function. Before we do that though, make sure that you have a default e-mail address assigned to the customer.
2012. All rights reserved.
Send Your
Confirmation
Now we will click on the Confirmation button and see what happens.
2012. All rights reserved.
Sending Your
Confirmation
I set a break point on the function just so that I could make sure that its running correctly, and it looks like it is.
2012. All rights reserved.
Sending Your
Confirmation
And also all of the standard logic is working as well.
2012. All rights reserved.
Sending Your
Confirmation
If you look at the Email Sending Status in the System Administration menu, you will also be able to see the e-mail as it is queuing up to be sent.
2012. All rights reserved.
E-Mail Sent
And now the customer also receives a confirmation without ant e-mail interaction from the customer service rep.
Very Cool.
About
Murray Fife