web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Like to insert line in custom table while creating new line in purchase order

(0) ShareShare
ReportReport
Posted on by 28

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!

I have the same question (0)
  • @rp@n Profile Picture
    28 on at
    RE: Like to insert line in custom table while creating new line in purchase order

    thanks Mohit & Girish

    done, through PurchLine - insert method

  • Verified answer
    Mohit Rampal Profile Picture
    12,563 Moderator on at
    RE: Like to insert line in custom table while creating new line in purchase order

    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.

  • @rp@n Profile Picture
    28 on at
    RE: Like to insert line in custom table while creating new line in purchase order

    Let me check,  will update you

  • GirishS Profile Picture
    27,825 Moderator on at
    RE: Like to insert line in custom table while creating new line in purchase order

    Yes it will be in PurchLine table.

    Thanks,

    Girish S.

  • @rp@n Profile Picture
    28 on at
    RE: Like to insert line in custom table while creating new line in purchase order

    thanks Girish,

    is it Purchline table - Validatewrite method ?

  • GirishS Profile Picture
    27,825 Moderator on at
    RE: Like to insert line in custom table while creating new line in purchase order

    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.

  • @rp@n Profile Picture
    28 on at
    RE: Like to insert line in custom table while creating new line in purchase order

    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

  • GirishS Profile Picture
    27,825 Moderator on at
    RE: Like to insert line in custom table while creating new line in purchase order

    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.

  • @rp@n Profile Picture
    28 on at
    RE: Like to insert line in custom table while creating new line in purchase order

    Hi Girish,

    pastedimage1685546791708v2.png

    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

    pastedimage1685546821543v3.png

    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

  • @rp@n Profile Picture
    28 on at
    RE: Like to insert line in custom table while creating new line in purchase order

    Let me check and will update you.

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

Mansi Soni – Community Spotlight

We are honored to recognize Mansi Soni as our August 2025 Community…

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

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

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans