Total discount is calculated automatically – Bug

Update: This issue was reported and has a hotfix that can be downloaded from Microsoft. Just create a new support issue on the partnersource and ask for the following:

Knowledge Base ID: 953178

Original post

The following checkbox ”Total discount is calculated automatically” makes sure that every order has its total discount calculated before it is posted.

Accounts Recievable/Setup/Parameters/Prices tab

AR - Parameters - Prices

This is done in the “clicked method” that executes when the posting button is clicked, this means that total discount is calculated on the sales order even before you get the dropdown where you can choose the different types of posting i.e. Invoice or Confirmation. But as it turns out, this does not seem work if you multiselect in the sales order form(Click thumbnail below to see the form).

SO - Multiselect

Only one of these orders will have its total discount calculated, in this case the one with the little arrow on the left which also happens to be the one I clicked on last then I performed the multiselect.

This is the code that triggers the calculation of the sales order total discount, as you can see this code is only run one time, on the current sales order.


A simple way to fix this is to use the Multi select functionality as described in one of my previous posts on this blog, this could look something like this.

Declare SalesTable:

SalesTable          localSalesTable;

Replace the call to the method automaticTotalDiscount with the following code:

    localSalesTable = SalesTable_ds.getFirst(true);
    if (localSalesTable)
        //Multiple selection
            localSalesTable = SalesTable_ds.getNext();
        } while (localSalesTable);

Remember, this is probably not the best way so solve this problem in terms of performance. The automaticTotalDiscount performes a reread and a refresh on the salestable form each time it’s called. It would probably be better if all the selected sales orders was updated before the form refreshes itself.

An even better solution to this problem can be found in the Dynamics AX 2009 environment where this calculation has been moved to the SalesFormLetter class. Just perform a search for the keyword “AutomaticTotalDiscount” and you will get the picture. I have not tried to move that functionality from 2009 to 4.0, but based on the code itself it shouldn’t be a problem as long as the calculation is performed before the SalesParmTable records is created.

Last 5 posts in Bugs

Leave a Reply

Your email address will not be published. Required fields are marked *