How to apply retail discount codes against Sales Order in AX client / AX 2012 R3 CU9

AX 2012 R3 CU9 has Discount code setup:
But there is no way how to apply Discount Codes to Sales Order. And unfortunately there is no logic in RetailOrderCalculator class which can feed sales order related discount codes to PricingEngine.
Fortunately PricingEngine is reaty to get and consider discount codes.
We need to do following:
1. Create post event to \Classes\RetailSalesOrderCalculator\initializeCrtTransaction method
public static void addSalesOrderDiscountCodes(XppPrePostArgs _args)
    Microsoft.Dynamics.Commerce.Runtime.DataModel.SalesTransaction crtSalesTransaction = _args.getReturnValue();
    CLRObject                   discountCodesList;
    RetailSalesOrderCalculator  retailSalesOrderCalculator  = _args.getThis();
    SalesId                     salesId                     = retailSalesOrderCalculator.getSalesId();
    SalesTableDiscountCodes     salesTableDiscountCodes;

    if (salesId)
        discountCodesList = crtSalesTransaction.get_DiscountCodes();
        while select DiscountCode from salesTableDiscountCodes
            where salesTableDiscountCodes.SalesId == salesId
SalesTableDiscountCodes is new table which contains 2 fields:
  • SalesId - link to sales order
  • DiscountCode - actualy discount code which customers should provide to use related discount
2. Create new method at \Classes\RetailSalesOrderCalculator class:
protected SalesId getSalesId()
    return salesId;
3. You also should provide a way to edit SalesTableDiscountCodes table. Basically it could be simple list form which can be shown from SalesTable form.

Classes which also involved in retail price calculation and may help:



About is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics AX.

Authors are allowed to set their own AdSense units.
Join us.

Blog Tags