Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / x++ - get purch(price)...
Finance forum
Suggested answer

x++ - get purch(price) agreement

Posted on by 330

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
    Sergei Minozhenko 23,083 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.

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

  • RE: D365 x++ - get purch(price) agreement

    Gunjan ,thank you

    my problem is that  priceDisc return null

    7652.png

  • 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
    Gunjan Bhattachayya 35,417 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
    Sergei Minozhenko 23,083 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
    vinitgoyal2005 6,326 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?

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,696 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,490 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans