Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Unanswered

getting two records on using OnINSERTING table event handler in d365

(0) ShareShare
ReportReport
Posted on by 1,479

I have created one table name "salesorderexim"   which is linked to "salesline" table  using  Recid of salesline table , i am trying to insert record in "salesorderexim"  using oninserting table event handler when i do entry in salesline , but i am getting 2 lines  on my salesorderexim  table . like oninserting code is creating another line its not insering record in same line .how can i insert without creating another line in my child table any suggestions plz. my code is below

   [DataEventHandler(tableStr(SalesLine), DataEventType::Inserting)]
    public static void SalesOrderEximLines_onInserting(Common sender, DataEventArgs e)
    {

        SalesLine    salesLine = sender as salesLine;
        SalesOrderEximLines   salesOrderEximLines;

                ttsbegin;
                salesOrderEximLines.RefRecId = salesLine.RecId;
                salesOrderEximLines.HSNCode =  HSNCodeTable_IN::find(InventTable::find(salesLine.ItemId).HSNCodeTable_IN).Code;
                salesOrderEximLines.insert();
                ttscommit;
    }

  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,479 on at
    RE: getting two records on using OnINSERTING table event handler in d365

    when  i was yousing  delayed join  i was getting desired output but in front end the entries wont shows properly in form but they are getting inserted in table.

  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,479 on at
    RE: getting two records on using OnINSERTING table event handler in d365

    hi,

    is it possible if i use form event handler to get these record populated in table  when new line is created in salesline

    as you said one record is inserted from form thats why i am asking.

  • Martin Dráb Profile Picture
    Martin Dráb 230,842 Most Valuable Professional on at
    RE: getting two records on using OnINSERTING table event handler in d365

    No, OnModified won't help.

    First of all, think about whether using an InnerJoin is a good idea. It means that no existing order line will be displayed, unless you generate records in your table for all existing order lines. You'd also had to be careful about data consistency. If the insert of SalesLine and your table wasn't in a transaction, users could create order lines that won't show in the form.

  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,479 on at
    RE: getting two records on using OnINSERTING table event handler in d365

    hi , 

    as you suggest one record is inserted from the form and one record is inserted from my insert event handler so what if i used onmodified event handler will it make change to the record which i need .

  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,479 on at
    RE: getting two records on using OnINSERTING table event handler in d365

    thanks for reply ,

     when i debug the code i am not getting the "Recid" value of newly created sales line in  debugger  so the  SALESORDEREXIMLINES.Refrecid field is getting blank and the a new line is getting created  when HSNCODE IS inserted.

  • Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,587 Super User 2024 Season 1 on at
    RE: getting two records on using OnINSERTING table event handler in d365

    If those fields are getting blank means, as Martin suggested try debugging the code.

    Also if you insert, it won't update the record rather it will create a new record.

  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,479 on at
    RE: getting two records on using OnINSERTING table event handler in d365

    when I try not to use any code to populate the record it will make the field HSNCODE  & RefrenceRecid  blank in table so thats why i am trying to insert method,

    i need these fields to be populated  (field HSNCODE  & RefrenceRecid) because the data from these field will reflect in my report.

  • Martin Dráb Profile Picture
    Martin Dráb 230,842 Most Valuable Professional on at
    RE: getting two records on using OnINSERTING table event handler in d365

    The best approach would be populating field values before the record is inserted by the sysytem. It would be straightforward and you wouldn't need extra database queries to load the record again and update it.

  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,479 on at
    RE: getting two records on using OnINSERTING table event handler in d365

    yes i have SalesOrderEximLines data source joined to SalesLine in the form,

    pastedimage1676014096836v1.png

    so if code is creating another record how can i insert values in the record which is created by form .

    do i have to use update method for this instead of oninserting event handler

    thanks ,

    regards dinesh

  • Martin Dráb Profile Picture
    Martin Dráb 230,842 Most Valuable Professional on at
    RE: getting two records on using OnINSERTING table event handler in d365

    If you have no idea about what is inserting the record, use the debugger to find it out. Put a breakpoint to insert() method, attach the debugger and test the process.

    Don't you have SalesOrderEximLines data source joined to SalesLine in the form? If so, one record is created by the form and the other by your code.

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,969 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,842 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans