Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / How to fetch value of ...
Finance forum
Suggested answer

How to fetch value of trade agreement journal line on sales line

(1) ShareShare
ReportReport
Posted on by 82
I am trying to find how the line amount is populating on sales line (Unit Price) when a trade agreement is  defined for that particular item, also if i post a trade agreement with same item say Item123 twice and define the price in Trade agreement 1 as 10 and in trade agreement 2 as 20 then if i post a sales order with item123 then everytime it will auto populate the sales line as unit price as 20 only.
Also if i click on SalesOrderLine in the ribbon and navigate to Price Details (MCRPriceHistory) then i can see only 1 trade agreement line, how is this possible also how is the trade agreement journal is coming up over there?
 
To sum up the above paragraph, Can someone help me in understanding this & finding the related objects, classes, x++ code for below :
1. How is trade agreement journal is getting related to sales orders when we navigate to price details, how and where does the value comes from
2. How to fetch the value of all the fields in trade agreement journal line to sales line, where to add the x++ code 
 
Please try to understand my requirement, Say i have 3 custom fields on Trade agreement journal line say Field1, Field2 and Field 3 added on PriceDiscAdmTrans.Extension, and I create a trade agreement for Item123 and give the value of Field1 = 10, Field2 = 20 and Field3 = ABC and post the journal.
 
I have the same fields Field1, Field2, Field 3  and JournalNumber custom fields added on SalesLine.Extension
 
Now when i create a sales order line with the same item which is Item123 i need these feilds on sales line to have a value autopopulated from trade agreement which will be:
Field1 = 10
Field2 = 20
Field 3 = 30
JournalNumber = ABC001 (Trade agreement journal number)
 
How do i achieve this using x++ code and where should i write my code which class which method??
 
 
  • CU05050618-0 Profile Picture
    CU05050618-0 12 on at
    How to fetch value of trade agreement journal line on sales line
    Great answer. I really appreciate your saying❤
  • How to fetch value of trade agreement journal line on sales line

    To achieve the desired behavior of populating custom fields on the SalesLine based on trade agreement values, you'll need to customize the logic in Dynamics 365 Finance and Operations (D365FO). Below is a general guide on how you can approach this using X++ code:
    Create Extended Data Types (EDTs) for Custom Fields:
    Define EDTs for your custom fields on both PriceDiscAdmTrans and SalesLine.
    Add Custom Fields to Tables:
    Add the custom fields to the PriceDiscAdmTrans and SalesLine tables. Make sure to add them to the Extension property group.
    Override SalesTableType and SalesLineType Classes:
    Override the SalesTableType and SalesLineType classes to include the new custom fields.
    Override SalesLine Form:
    If necessary, modify the SalesLine form to display the new custom fields.
    Create Event Handlers:
    Create event handlers for the insert and update methods on the SalesLineType table, where you'll write the logic to fetch values from the trade agreement.
    Use PriceDiscAdmTrans Table:
    In your event handler, query the PriceDiscAdmTrans table to get the values from the trade agreement. You can use the ItemId and other relevant fields to filter the trade agreement records.
    Populate Custom Fields:
    Once you have the trade agreement records, populate the custom fields on the SalesLine based on the values retrieved from the trade agreement.
    Consider Using the PriceDiscEngine Class:
    Depending on your version of D365FO, you may also want to explore using the PriceDiscEngine class for handling price and discount-related functionality.
    Test Thoroughly:
    After implementing the changes, thoroughly test the functionality to ensure that the custom fields are populated correctly based on the trade agreement.
    Consider Performance Impact:
    Keep in mind the potential performance impact, especially if there are a large number of trade agreements or sales orders. Optimize your code to make it efficient.
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 284,876 Super User on at
    How to fetch value of trade agreement journal line on sales line
    Hi,
     
    I'm not able to quickly find the places as it looks like there are differences compared to the last time I applied some customizations in this area. Probably due to the new Global Unified Pricing. If you are not able to find the places using the debugger, you can consider recording a trace and check within the Trace Parser what calls are being done when e.g. entering an item or quantity.
     
    Note that the trade agreement journal lines are posted to the table PriceDiscTable. Do you have your new fields also added in this table to get it closer to the price search from sales order lines?
  • Community member Profile Picture
    Community member 82 on at
    How to fetch value of trade agreement journal line on sales line
    Please try to understand my requirement, Say i have 3 custom fields on Trade agreement journal line say Field1, Field2 and Field 3 added on PriceDiscAdmTrans.Extension, and I create a trade agreement for Item123 and give the value of Field1 = 10, Field2 = 20 and Field3 = ABC and post the journal.
     
    I have the same fields Field1, Field2, Field 3  and JournalNumber custom fields added on SalesLine.Extension
     
    Now when i create a sales order line with the same item which is Item123 i need these feilds on sales line to have a value autopopulated from trade agreement which will be:
    Field1 = 10
    Field2 = 20
    Field 3 = 30
    JournalNumber = ABC001 (Trade agreement journal number)
     
    How do i achieve this using x++ code and where should i write my code which class which method??
  • Community member Profile Picture
    Community member 82 on at
    How to fetch value of trade agreement journal line on sales line
    Hi, i get it that the calculations are done on PriceDisc class but my question is still the same, after selecting the item on sales order lines the unit price gets updated(autopopulated) from trade agreement for that item, where is this code written to update unit price from trade agreement because i debugged and couldn't find it, can someone help me with that
     
    because my requirement is on my trade agreement journal line i will add more fields(custom fields) and the way the unit price gets auto populated on sales line the similar way i will get value for the other fields but for that i need to figure out the place, method where this unit price gets inserted from trade agreemnt so i can create coc of that clas sto add my rest of the logic for custom fields
     
    please can someone let me know that part coz i am not able to get it
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 284,876 Super User on at
    How to fetch value of trade agreement journal line on sales line
    Hi,
     
    The logic to find prices is done within the class PriceDisc. It will find one of the two records based on a sorting index. In case you enable the option Find next on the trade agreement, it will continue searching for the best price for the customer. Anyway, in case of price changes, you can manage the validity dates which will then ensure that the system will fetch the correct price.
  • Suggested answer
    Community member Profile Picture
    Community member 2,368 on at
    How to fetch value of trade agreement journal line on sales line
    Hello,
     
    Try the below code and let us know how it goes.
    class DemoClass 
    {
        public static price findPurchPrice(ItemId _itemId, CustAccount _custAccount, InventDimId _inventDimId, VendAccount _vendAccount)
    
        {
    
            InventTable				inventTable		= InventTable::find(_itemId);
    
            CustTable				custTable		= CustTable::find(_custAccount);
    
            InventDim				inventDimItem	= InventDim::find(_inventDimId);
    
            VendTable               vendTable       =   VendTable::find(_vendAccount).PriceGroup;    
    
            UnitOfMeasureSymbol     unitId          = inventTable.inventTableModuleInvent().UnitId;
    
            PriceDisc				priceDisc;
    
            Price					retprice;
    
    
    
            PriceDiscParameters parameters = PriceDiscParameters::construct();
    
    
    
            parameters.parmModuleType(ModuleInventPurchSales::Sales);
    
            parameters.parmItemId(inventTable.ItemId);
    
            parameters.parmInventDim(inventDimItem);
    
            parameters.parmUnitID(unitId);
    
            parameters.parmPriceDiscDate(DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone()));
    
            parameters.parmQty(1);
    
            parameters.parmAccountNum(custTable.AccountNum);
    
            parameters.parmCurrencyCode(custTable.Currency);
    
            priceDisc = PriceDisc::newFromPriceDiscParameters(parameters);
    
            
    
            // From Trade agreement
    
            if (priceDisc.findPrice(vendTable.PriceGroup))
    
            {
    
                retPrice	= priceDisc.price();
    
            }
    
            //From Item
    
            else if (priceDisc.findItemPrice())
    
            {
    
                retPrice	= priceDisc.price();
    
            }
    
            return retprice;
    
        }
    }
    
     

    Please mark verify if this resolves your issue and help community.

    Regards

    Mav

Helpful resources

Quick Links

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Blog subscriptions now enabled!

Follow your favorite blogs

TechTalk: How Dataverse and Microsoft Fabric powers ...

Explore the latest advancements in data export and integration within ...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 284,876 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,425 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,146

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans