This post is machine-translated. The original post in german language can be found here.

Enter price information on order lines through code and control price search

A common requirement in projects is that sales order lines should be created by code, such as data imports or similar.

Recently I had the request that code-generated sales order lines are then to be processed manually, but the price information such as sales price and rebate should be preserved.

However, editing certain fields in a sales order line in Dynamics AX triggers price search. This had to be prevented or pointed out to the user at least by a query. Fortunately, there is already one such query, which is controlled by the following fields:

Field Description
ManualEntryChangepolicy Reference to table PriceDiscChangePolicy
SystemEntryChangePolicy Reference to table PriceDiscChangePolicy
SystemEntrySource BaseEnum

If you manually override the price in a sales order line, AX will take care of filling these fields and mark the price information as manually changed.

For example, if you change the order quantity, the following dialog opens:

Screenshot

Whether this dialog opens is controlled by Accounts receivable parameters > Prices > Trade agreement evaluation.

However, the above fields are only filled by AX in certain circumstances. You have to explicitly take care of these fields when creating a sales order line by code.

If you do not do this, the pricing information written by code will be overwritten if anything happens with the sales order line triggers a price search.

Below you will find a few examples of how to create a sales order line by code, setting the fields in such a way that if the price-relevant fields in the item change, the dialog described above opens. In all these examples, I act as if the prices had been entered manually, which is controlled by the BaseEnum PriceDiscSystemSource.

Create a sales order line using AxSalesLine

For each manually populated price field, the method setPriceDiscChangePolicy() must be called.

static void createSalesLine(Args _args)
{
    AxSalesLine axSalesLine;
    SalesLine salesLine;

    salesLine.clear();
    salesLine.salesId = "001060";
    salesLine.modifiedField(fieldNum(salesLine, SalesId));
    salesLine.ItemId = "D0001";
    salesLine.modifiedField(fieldNum(salesLine, ItemId));
    salesLine.SalesQty = 5;
    salesLine.modifiedField(fieldNum(salesLine, SalesQty));

    salesLine.SalesPrice = 499.99;
    salesLine.modifiedField(fieldNum(salesLine, SalesPrice));

    salesLine.LineDisc = 10.00;
    salesLine.modifiedField(fieldNum(salesLine, LineDisc));

    salesLine.LinePercent = 20.00;
    salesLine.modifiedField(fieldNum(salesLine, LinePercent));

    salesLine.PriceUnit = 1.00;
    salesLine.modifiedField(fieldNum(salesLine, PriceUnit));
    
    salesLine.setPriceDiscChangePolicy(
        PriceDiscSystemSource::ManualEntry,
        fieldNum(salesLine, SalesPrice));
    salesLine.setPriceDiscChangePolicy(
        PriceDiscSystemSource::ManualEntry,
        fieldNum(salesLine, LineDisc));
    salesLine.setPriceDiscChangePolicy(
        PriceDiscSystemSource::ManualEntry,
        fieldNum(salesLine, LinePercent));
    salesLine.setPriceDiscChangePolicy(
        PriceDiscSystemSource::ManualEntry,
        fieldNum(salesLine, PriceUnit));

    axSalesLine = new axSalesLine();
    axSalesLine.continueOnError(false);
    axSalesLine.validateInput(true);

    axSalesLine.salesLine(salesLine);

    axSalesLine.save();
}

 

Create a sales order line using SalesLine.create()

For each manually populated price field, the method setPriceDiscChangePolicy() must be called.

static void createSalesLine(Args _args)
{
    SalesLine salesLine;

    salesLine.clear();
    salesLine.salesId = "001060";
    salesLine.modifiedField(fieldNum(salesLine, SalesId));
    
    salesLine.ItemId = "D0001";
    salesLine.modifiedField(fieldNum(salesLine, ItemId));
    
    salesLine.SalesQty = 5;
    salesLine.modifiedField(fieldNum(salesLine, SalesQty));

    salesLine.SalesPrice = 499.99;
    salesLine.modifiedField(fieldNum(salesLine, SalesPrice));

    salesLine.LineDisc = 10.00;
    salesLine.modifiedField(fieldNum(salesLine, LineDisc));

    salesLine.LinePercent = 20.00;
    salesLine.modifiedField(fieldNum(salesLine, LinePercent));

    salesLine.PriceUnit = 1.00;
    salesLine.modifiedField(fieldNum(salesLine, PriceUnit));
    
    salesLine.setPriceDiscChangePolicy(
        PriceDiscSystemSource::ManualEntry,
        fieldNum(salesLine, SalesPrice));
    salesLine.setPriceDiscChangePolicy(
        PriceDiscSystemSource::ManualEntry,
        fieldNum(salesLine, LineDisc));
    salesLine.setPriceDiscChangePolicy(
        PriceDiscSystemSource::ManualEntry,
        fieldNum(salesLine, LinePercent));
    salesLine.setPriceDiscChangePolicy(
        PriceDiscSystemSource::ManualEntry,
        fieldNum(salesLine, PriceUnit));
    
    salesLine.createLine(
        true,
        true);
}

Incidentally, the above described applies not only to sales order lines, but also, for example, to purchase order lines.

Create a purchase order line using AxPurchLine

static void createPurchLine(Args _args)
{
    AxPurchLine axPurchLine;
    PurchLine purchLine;
    
    axPurchLine = AxPurchLine::newPurchLine(purchLine);
    axPurchLine.validateInput(true);
    axPurchLine.continueOnError(false);
    
    axpurchLine.parmPurchId("000036");
    axpurchLine.parmItemId("C0004");
    axPurchLine.parmPurchQty(10);
    axPurchLine.parmPurchPrice(24.50);
    
    axPurchLine.purchLine().setPriceDiscChangePolicy(
        PriceDiscSystemSource::ManualEntry,
        fieldNum(PurchLine, PurchPrice));    
    
    axPurchLine.save();
}

 

More detailed information can also be found in the document "Trade agreement evaluation policies in Microsoft Dynamics AX 2012".

 

These post applies to following version:
Dynamics AX 2012

 
 

 

 
 
 
Posts of the actual month
November 2024
MoTuWeThFrSaSu
 123
45678910
11121314151617
18192021222324
252627282930 
 
© 2006-2024 Heinz Schweda | Imprint | Contact | German version | Mobile version
In order to provide you with better service, this site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.