Skip to main content

Notifications

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 ..

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,091 on at
    RE: D365 x++ - get purch(price) agreement

    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.

  • Ahmed Osama Ibrahim Profile Picture
    332 on at
    RE: D365 x++ - get purch(price) agreement

            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()

  • Ahmed Osama Ibrahim Profile Picture
    332 on at
    RE: D365 x++ - get purch(price) agreement

    Gunjan ,thank you

    my problem is that  priceDisc return null

    7652.png

  • Ahmed Osama Ibrahim Profile Picture
    332 on at
    RE: D365 x++ - get purch(price) agreement

    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 .

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: D365 x++ - get purch(price) agreement

    Hi Ahmad,

    Can you try this line and try ?

    priceDisc.findItemPrice();

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,091 on at
    RE: D365 x++ - get purch(price) agreement

    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();

  • vinitgoyal2005 Profile Picture
    6,330 on at
    RE: D365 x++ - get purch(price) agreement

    Hi Ahmed Osamam,

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

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

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

#1
Martin Dráb Profile Picture

Martin Dráb 456 Most Valuable Professional

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 310

#3
Saalim Ansari Profile Picture

Saalim Ansari 261

Overall leaderboard

Product updates

Dynamics 365 release plans