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

how to retreive data from PurchParmLine table using x++ ?

(1) ShareShare
ReportReport
Posted on by 406
hi everyone, 
 
i want to retreive data from PurchParmLine table to get the line amount and unit price amounts to my product receipt report.
can anyone provide me the correct relation to use in the DP class to make this happen?
 
i have tried this but its not working and returning null:
 
    [DataEventHandler(tableStr(PurchPackingSlipTmp), DataEventType::Inserting)]
    public static void PurchPackingSlipTmp_onInserting(Common sender, DataEventArgs e)
    {
        PurchPackingSlipTmp purchPackingSlipTmp = sender as PurchPackingSlipTmp;
        if (purchPackingSlipTmp)
        {
            PurchParmLine purchParmLine;
            PurchTable purchTable;
            PurchLine purchLine;
            // Fetch the PurchTable record
            select firstOnly purchTable
            where purchTable.PurchId == purchPackingSlipTmp.PurchId;
            if (purchTable)
            {
                // Fetch the PurchLine record
                select firstOnly purchLine
                where purchLine.PurchId == purchTable.PurchId;
                if (purchLine)
                {
                    // Fetch the PurchParmLine record
                    select firstOnly purchParmLine
                    where purchParmLine.PurchLineRecId == purchLine.RecId;
                    if (purchParmLine)
                    {
                        purchPackingSlipTmp.PurchPrice = purchParmLine.PurchPrice;
                        purchPackingSlipTmp.LineAmount = purchParmLine.LineAmount;
                    }
                }
            }
        }
    }
 
 
  • Suggested answer
    Martin Dráb Profile Picture
    241,467 Most Valuable Professional on at
    You need ParmId to identify the correct set of PurchParmLine records. You try to find it by PurchId only, but it can't work correctly, because a single order may be used in many packing slip postings.
     
    Also, PurchPackingSlipTmp is normally used by in PurchPackingSlipDP, which shows information about packing slip journals (VendPackingSlipJour and VendPackingSlipTrans tables), not PurchParm* tables. Those parm tables are used just as an input for creating a journal and they don't have to exist anymore when the journal is printed. Are you 100% sure that you want to show these parameters instead of the actual packing slip journals?
  • D365FO DEV Profile Picture
    406 on at
    Hello martin,
     
    all i want is to retreive the unit price and net amount of each PO line. i just the correct select statement to implement it in the DP so i can map those fields to my fields in my table.
  • Martin Dráb Profile Picture
    241,467 Most Valuable Professional on at
    Using Net amount from the PO line would be wrong, because that may be for a different quantity than the journal line. Also, don't forget that it may change over time - if you want your report to show values that were valid when creating the journal, you must save them in the journal instead of using current values from the order.
     
    First of all, check out if the information isn't already in VendPackingSlipTrans. Namely, ValueMST may cover your requirements regarding the total amount.
     
    If not and you want to store current values in VendPackingSlipTrans, extend either VendPackingSlipTrans.initFromPurchLine() (for data from PurchLine, such as the unit price) or PurchParmPackingSlipJournalCreate.updateJournalLine() (for data from PurchParmLine, such as LineAmount).
     
    If you're fine with using the unit price from the order line, you don't need PurchParmLine. Simply find the PurchLine record by VendPackingSlipTrans.InventTransId.
  • D365FO DEV Profile Picture
    406 on at

    For the line amount its working fine using ValueMST, i need now the unit price.
    can you provide me with correct code on how to find the PurchLine record by VendPackingSlipTrans.InventTransId.
    because i have tried one but its not working, here is my code:
     
    [DataEventHandler(tableStr(PurchPackingSlipTmp), DataEventType::Inserting)]
        public static void PurchPackingSlipTmp_onInserting(Common sender, DataEventArgs e)
        {
            PurchPackingSlipTmp purchPackingSlipTmp = sender as PurchPackingSlipTmp;
            purchLine purchLine;
            vendPackingSlipTrans vendPackingSlipTrans;
            select VendPackingSlipTrans 
                where PurchPackingSlipTmp.VendPackingSlipTrans == VendPackingSlipTrans.RecId;
            select firstOnly purchLine
                    where purchLine.InventTransId == vendPackingSlipTrans.InventTransId;
            purchPackingSlipTmp.PurchPrice = purchLine.PurchPrice;
        }
  • Suggested answer
    Martin Dráb Profile Picture
    241,467 Most Valuable Professional on at
    You're doing it at the wrong place.
     
    Create a CoC extension of PurchPackingSlipDP.initializeProductReceiptLine() and then simply call _receiptLineSelection.parmVendPackingSlipTrans().purchLine().
  • D365FO DEV Profile Picture
    406 on at
    thanks
  • Martin Dráb Profile Picture
    241,467 Most Valuable Professional on at
    That's a bug in your code that you didn't show. It seems that you take the table buffer and try to assign to a number, which is impossible. You can't implicitly convert a table to a number. Most likely, you wanted to select a field from the table, you forgot to do it and you didn't pay enough attention to what the error message was telling you.

    Update: The previous reply was about an error complaining that PurchLine can't be assigned to real. Unfortunately, D365FO_ERP_Developer later replaced the whole reply with mere thanks, which ruined this thread of discussion.
  • Waed Ayyad Profile Picture
    9,222 Super User 2026 Season 2 on at
    Hi,
     
    Did you try to debug the code? What do you mean it returning null?  Do you mean the report isn't returning data? 
     
    Thanks,
    Waed Ayyad
     
     
     
     
     

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

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

#1
Martin Dráb Profile Picture

Martin Dráb 539 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 366 Super User 2026 Season 2

#3
CU-1234529-002 Profile Picture

CU-1234529-002 197

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans