Skip to main content

Notifications

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

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!

  • @rp@n Profile Picture
    @rp@n 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
    Mohit Rampal 12,552 Super User 2024 Season 1 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
    @rp@n 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
    GirishS 27,821 Super User 2024 Season 1 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
    @rp@n 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
    GirishS 27,821 Super User 2024 Season 1 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
    @rp@n 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
    GirishS 27,821 Super User 2024 Season 1 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
    @rp@n 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
    @rp@n 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

Announcing Our 2025 Season 1 Super Users!

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

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,817 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans