Thursday, March 10, 2011

Email Invoices based on customer setup options - Microsoft Dynamics Ax 2009

Today I had a requirement that said to add a CheckBox control to the Customer Form to decide weather to print or email an invoice automatically.


NOTE: I will no go over the actual logic on how to email the invoice as I have already written a post about it, you can find it here http://axwonders.blogspot.com/2011/02/save-microsoft-dynamics-ax-2009-report_23.html


The following is the new control added to the CustTable form under the setup Tab:





 Now the logic is very simple. If the a customer account has this checkbox checked then set the Document destination value automatically to Email. Otherwise set the value of the control to Printer. In the picture above we can see that this specific customer has the checkbox checked.


Then the expected result will be to see the Document destination value to Email when a sales order record needs to be invoiced or acknowledged.


Please see the following sequence:








The other scenario will be to unchecked the checkbox in the customer form and the result should be the following:



So, how did accomplish this?

1- Create a new method in the SalesEditLinesForm class with a return of Type enum (this can be any custom enum) mine is called glPrintType and has three enum values - Email, Printer, and Preview


public glPrintType setDocDestination(SalesId _salesId)
{
    NoYes           checked;
    ;

    checked = CustTable::find(SalesTable::find(_salesId, false).CustAccount, false).emailInvoice;

    if(checked)
        return glPrintType::Email;
    else
        return glPrintType::Printer;

}


2- Add the following line of code to the Run() method of the SalesEditLines Form. Just make sure you place this code after setting the query for the salesFormLetter class.

...

salesParmUpdate_ds.object(fieldnum(SalesParmUpdate, DocDestination)).setValue(salesEditLinesForm.setDocDestination(salesParmTable.SalesId));
...

We basically set the value of the salesParmUpdate data source. The object will be initialized based on the table SalesParmUpdate and field DocDestination.

Then we call the setValue() method and within this method we call the SalesEditLineForm class custom method setDocDestination (shown above).




2 comments:

  1. Call us at We24Support E-mail support number at 1-866-978-0799 and Enhance your system functioning and keep it clean with We24Support services.
    E mail Setup and Support
    email support

    ReplyDelete
  2. I had to do something similar but we're auto-invoicing in large batches with specific controls. We also needed a history to see what invoices were sent, while this printer/email solution doesn't track that. To use AX2009's base emailing framework, SysEmailTable::sendMail(...) will throw it in there.

    ReplyDelete

Thank you for your thoughts. Your comment will appear in my blog shortly after review.

Have a great day!