Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

Get Unit Price from Purchase Agreement with X++ Code

Posted on by 325

My end goal is to get the unit price for an item from a purchase agreement with X++ code. I'm having a hard time figuring out where to access this information. All I currently have available to me in my code is the Vendor information and the item, but not even what Purchase Agreement Number. I'm working with the assumption that a vendor will not have a given item in multiple PA's.

My first thought is to find the PA and then access the PA Lines to get the Unit Price for the item. If there's a better way I would love to hear it. Currently in the All Vendors List Page you can click the Procurement Tab and then the Purchase Agreements Button with a vendor selected to be taken to the Purchase Agreements List Page filtered to just that vendor. I can't figure out how to duplicate this functionality in my own code. Since I have the vendor information already my plan is to find all the PA's for that vendor, then search the PA's for the item I'm looking for and then get the Unit Price for that item from the PA Line.

I'm not sure this is the way I should be trying to do this, but it's the best idea I have for accessing this information, presently.

  • Pranav Gupta Profile Picture
    Pranav Gupta 145 on at
    RE: Get Unit Price from Purchase Agreement with X++ Code

    If you want to do this in D356O, check the below link as "PriceDisc::findItemPriceAgreement()" is deprecated in D365O.

    1824pranav.blogspot.com/.../find-price-disc-trade-agreements-in.html

  • ron_ron Profile Picture
    ron_ron 180 on at
    RE: Get Unit Price from Purchase Agreement with X++ Code

    Hi

    Did you solve this?

    Thanks.

  • Tyler1986 Profile Picture
    Tyler1986 325 on at
    RE: Get Unit Price from Purchase Agreement with X++ Code

    Ok, I found out I am getting results, just not what I'm looking for. Right now I'm getting the price from the item details page where you set a purchase price:

    desiredprice.png

    But I'm looking for the price from a purchase agreement: 

    My updated code is:

    static void GetPriceFromItemAndVendor(Args _args)
    {
        InventTable                 inventTable = inventTable::find('10000');
        InventDim inventDim;
        ItemId ItemId;
        UnitOfMeasureSymbol UnitId;
        TransDate TransDate;
        PriceDisc PriceDisc;
        container result;
    
        InventDim.initFromInventTable(inventTable);
        
        ItemId = "10000";
        UnitId = "Pcs";
        TransDate = today();
    
        result = PriceDisc::findItemPriceAgreement(ModuleInventPurchSales::Purch, ItemId, inventDim, UnitId, TransDate, 10000, "1001",
                                "USD", "0");
    
    }

    Which returns 399 as the price.

  • Tyler1986 Profile Picture
    Tyler1986 325 on at
    RE: Get Unit Price from Purchase Agreement with X++ Code

    edit: Updated below. Unsure on how to delete a post.

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Get Unit Price from Purchase Agreement with X++ Code

    Please ensure that you have data as per the parameter you are passing

    like

    Inventory Dimension

    UnitId and valid price agreement data for today

    Please review and update us with your findings

  • Tyler1986 Profile Picture
    Tyler1986 325 on at
    RE: Get Unit Price from Purchase Agreement with X++ Code

    Thanks for introducing me to this class, it is just what I need, although I am having trouble learning to use it my first time. I'm writing a job to try and get an example of this working. Below is the code I have so far, it compiles and runs fine, but the container just contains zeros for the most part so I assume it is not finding anything. It's likely a problem with the parameters I am giving the method,  being my first time attempting to use it and an unfamiliarity with the parameter types I'm sure I've made some mistakes.

        InventDim InventDim;
        ItemId ItemId;
        UnitOfMeasureSymbol UnitId;
        TransDate TransDate;
        PriceDisc PriceDisc;
        container result;
        
        
        InventDim = InventDim::findOrCreateBlank();
        ItemId = "10000";
        UnitId = "Pcs";
        TransDate = today();
        
        result = PriceDisc::findItemPriceAgreement(ModuleInventPurchSales::Purch, ItemId, InventDim, UnitId, TransDate, 10000, "1001","USD", "0");

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Get Unit Price from Purchase Agreement with X++ Code

    please utilize following link with more details

    msdn.microsoft.com/.../pricedisc.finditempriceagreement.aspx

    Please verify and let us know if this helps you

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Get Unit Price from Purchase Agreement with X++ Code

    Use the following method of PriceDisc class.

    static container findItemPriceAgreement(ModuleInventPurchSales  _moduleType,

                                           ItemId                  _itemId,

                                           InventDim               _inventDim,

                                           UnitOfMeasureSymbol     _unitID,

                                           TransDate               _priceDate,

                                           Qty                     _qty,

                                           CustVendAC              _accountId,

                                           CurrencyCode            _currency,

                                           PriceGroupId            _priceGroupId)

    {

       PriceDisc       priceDisc;

       ;

       priceDisc = new PriceDisc(_moduleType,

                                 _itemId,

                                 _inventDim,

                                 _unitID,

                                 _priceDate,

                                 _qty,

                                 _accountId,

                                 _currency);

       priceDisc.findPrice(_priceGroupId);

       return [priceDisc.price(),

               priceDisc.markup(),

               priceDisc.priceUnit(),

               priceDisc.deliveryDays(),

               priceDisc.calendarDays()];

    }

    It will give you a container containing Price unit.

    Hope this helps you

Helpful resources

Quick Links

Can you answer this forum question?

You could make someone's day!

Community Newsletter - May 2024

Kudos to our community stars!

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 283,663 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 224,741 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,146

Featured topics

Product updates

Dynamics 365 release plans