Hi All,
As per my requirement, When we create a lines on Purchase Order, at the same time I like to insert the same line on my Custom table.
Say for example - I have Purchase Order - P001 and I have created 5 lines
So, i like to insert those 5 lines in my custom table. but for me it is inserted only the last line when I finally click CTRL S once.
I wrote below code, Can anyone pls verify where is wrong? why it is NOT inserted all he lines in my custom table ?
class PurchLineOnInsertingEventHandler { ////// /// /// /// [DataEventHandler(tableStr(PurchLine), DataEventType::Inserting)] public static void PurchLine_onInserting(Common sender, DataEventArgs e) { PurchLine purchLine = sender as PurchLine; PurchQtyTracking purchQtyTracking; PurchParameters purchParameters; purchParameters = PurchParameters::find(); if (purchParameters.QtyZeroPOLines == NoYes::Yes) { // to insert the current record only ttsbegin; purchQtyTracking.PurchId = purchLine.PurchId; purchQtyTracking.ItemId = purchLine.ItemId; purchQtyTracking.RefRecId = purchLine.RecId; purchQtyTracking.doInsert(); ttscommit; } } }
Pls give me more shed on this.
thanks!
thanks Mohit & Girish
done, through PurchLine - insert method
Hi, Please debug doApply method in PurchQuickQuote form. It calls insert method of PurchLine table one by one for all selected records. Also add breakpoint on insert method of PurchLine.
Let me check, will update you
Yes it will be in PurchLine table.
Thanks,
Girish S.
thanks Girish,
is it Purchline table - Validatewrite method ?
First check whether the validateWrite method at table level is calling without clicking save button.
Refer to the below code - You need to validate the records before inserting into custom table.
PurchLine purchLine = sender as PurchLine; PurchQtyTracking purchQtyTracking,purchQtyTrrackingValidate; PurchParameters purchParameters; purchParameters = PurchParameters::find(); if (purchParameters.QtyZeroPOLines == NoYes::Yes) { //add select statement to validate the record in custom table select firstonly * from purchQtyTrackingValidate where purchQtyTrackingValidate.RefRecId == purchLine.RecId; if(!purchQtyTrackingValidate) { // to insert the current record only ttsbegin; purchQtyTracking.PurchId = purchLine.PurchId; purchQtyTracking.ItemId = purchLine.ItemId; purchQtyTracking.RefRecId = purchLine.RecId; purchQtyTracking.doInsert(); ttscommit; } }
Thanks,
Girish S.
Hi Girish,
Sorry I not understood.
ValidateWrite method --
"In that case you need to validate the custom table to check whether the current record is there or not - If there do not insert - If not there do a insert operation."
kindly elaborate pls
Try adding your code in the validateWrite event handler of the table. In that case you need to validate the custom table to check whether the current record is there or not - If there do not insert - If not there do a insert operation.
Refer to the below blog. Follow the table level validate Write event handler.
https://d365solution.blogspot.com/2019/11/validatedwrite-eventhandler-d365-at.html
Thanks,
Girish S.
Hi Girish,
When I clicked on Addlines, my eventhandler is NOT getting called.
when I completed the line and press CTRL+S then only called the event handler code
But I am looking for each line to insert in my custom table without press CTRL +S.
Where to write the code? In which method
Please guide me
Let me check and will update you.
André Arnaud de Cal...
291,965
Super User 2025 Season 1
Martin Dráb
230,817
Most Valuable Professional
nmaenpaa
101,156