Creating Automatic Email Confirmations From Dynamics AX
Posted by Author, Curator, Visually Impared Squirrel Literacy Advocate & Dynamics AX Technical Solution Professional (TSP) at Microsoft on
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.
Step 1: 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. |
Step 2: 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. |
After you open up the form, you will want to create a new template. |
And also create a new e-mail layout. |
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 “%”. |
After you have done this, you can preview the e-mail. |
Step 3: 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. |
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. |
Step 4: Create A New Project |
Rather than change the form directly, it’s better to wrap the code within a project. So we will create a new project. |
Now we will drag the form design from AOT over to the project. |
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. |
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. |
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. |
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. |
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. |
Step 5: Send Your E-mail |
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. |
Now we will click on the Confirmation button and see what happens. |
I set a break point on the function just so that I could make sure that it’s running correctly, and it looks like it is. |
And also all of the standard logic is working as well. |
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. |
Result: E-mail Sent |
And now the customer also receives a confirmation without ant e-mail interaction from the customer service rep. |
Very Cool!
SlideShare Presentation: http://www.slideshare.net/murrayfife/creating-automatic-sales-order-email-confirmations-in-dynamics-ax-2012
Original: http://sdrv.ms/OI8tFV
Share this post
- 0 comment
- Tags: Dynamics AX
0 comment