web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

x++ - get purch(price) agreement

(0) ShareShare
ReportReport
Posted on by 332

Hello..

I need to get purch price agreement  so.

first I create purch price agreement for testing and applied  it in purch price

First I created  it from Trade agreement journals

376862.png

26846.png

and this applied in PurchLine without problems..

now I need to don't allow PurchPrice to be greater than the price on journal

SO I created a class as below

class BT_PurchTable_Table_VaildatePriceAggrement
{

    /// 
    ///
    /// 
    /// 
    [PostHandlerFor(tableStr(PurchLine), tableMethodStr(PurchLine, validateField))]
    public static void PurchLine_Post_validateField(XppPrePostArgs args)
    {
        PurchLine purchLine = args.getThis();

        InventDim   inventDim;
        inventDim = InventDim::find(purchLine.InventDimId);

        PriceDiscParameters parameters = PriceDiscParameters::construct();
        
        parameters.parmModuleType(ModuleInventPurchSales::Purch);
        parameters.parmItemId(purchLine.ItemId);
        parameters.parmInventDim(inventDim);
        parameters.parmUnitID(purchLine.PurchUnit);
        parameters.parmPriceDiscDate(systemDateGet());
        parameters.parmQty(purchLine.PurchQty);
        parameters.parmAccountNum(purchLine.VendAccount);
        parameters.parmCurrencyCode(purchLine.CurrencyCode);
        
        PriceDisc priceDisc = PriceDisc::newFromPriceDiscParameters(parameters);

        
        FieldId fieldId = args.getArg("fieldId");

        boolean ret = args.getReturnValue();
 
        switch(fieldId)
        {
            case fieldNum(purchLine, PurchPrice):

                
            if (purchLine.PurchPrice > priceDisc.priceUnit())
            {
                ret = ret && checkFailed("Line per cent is to high!");
            }
            break;
        }
 
        args.setReturnValue(ret);
    }

}

but priceDisc.priceUnit()  or priceDisc.price() always return 0

when I tested my code in Runable class

class getPrice
{
    /// 
    /// Runs the class with the specified arguments.
    /// ☻
    /// The specified arguments.
    public static void main(Args _args)
    {
        PurchLine purchLine =PurchLine::find("00000126",2);

        InventDim   inventDim;
        inventDim = InventDim::find(purchLine.InventDimId);

        PriceDiscParameters parameters = PriceDiscParameters::construct();
        
        parameters.parmModuleType(ModuleInventPurchSales::Purch);
        parameters.parmItemId(purchLine.ItemId);
        parameters.parmInventDim(inventDim);
        parameters.parmUnitID(purchLine.PurchUnit);
        parameters.parmPriceDiscDate(systemDateGet());
        parameters.parmQty(purchLine.PurchQty);
        parameters.parmAccountNum(purchLine.VendAccount);
        parameters.parmCurrencyCode(purchLine.CurrencyCode);
        
        PriceDisc priceDisc = PriceDisc::newFromPriceDiscParameters(parameters);

        info(strFmt("%1",priceDisc.price()));
        info(strFmt("%1",priceDisc.priceUnit()));
        info(strFmt("%1",priceDisc.findItemPrice()));
    }

}

when debug the Runable class

parameters returns the PurchLine

5415.png

 PriceDisc return nothing

03548.png

So how I can return the PurchPrice agreement ?

Thank you ..

I have the same question (0)
  • vinitgoyal2005 Profile Picture
    6,332 on at

    Hi Ahmed Osamam,

    The code looks correct, Did you check if the data exists in purchase agreements for that item/invetDim/Vendor combination?

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,097 on at

    Hi Ahmed,

    It could be that some search parameters in your code don't match parameters from purch line.

    Try to use the same code as in PurchLine to get price

    purchLine.salesPurchLineInterface().priceDisc_PriceCache(purchLine.InventDim(), true).price();

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,429 on at

    Hi Ahmad,

    Can you try this line and try ?

    priceDisc.findItemPrice();

  • Ahmed Osama Ibrahim Profile Picture
    332 on at

    Sergei really  thank you ,it's return the right value from agreement.

    It could be that some search parameters in your code don't match parameters from purch line.

    In my job I pointed to the PO and line that applied the agreement so i think no problem in my data , maybe there some information not inserted in the parameters ,Also I reviewed all the data manually .

  • Ahmed Osama Ibrahim Profile Picture
    332 on at

    Gunjan ,thank you

    my problem is that  priceDisc return null

    7652.png

  • Ahmed Osama Ibrahim Profile Picture
    332 on at

            if (priceDisc.findPrice(VendTable::find(purchLine.VendAccount).PriceGroup))
            {
                retPrice = priceDisc.price();
            }

    this code return the right value ,but I didn't understand why I need to use PriceGroup in findPrice()

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,097 on at

    Hi Ahmed,

    If you check the method implementation "purchLine.salesPurchLineInterface().priceDisc_PriceCache(purchLine.InventDim(), true)"you will see that price group is set for PriceDisc from PurchTable (and before it's copied from Vendor), but PriceDiscParameters doesn't cover it in your code.

    That's why I recommend using the same method if you need to be sure to have the same behavior.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 797

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 589 Super User 2026 Season 1

#3
Subra Profile Picture

Subra 534

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans