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, ...
Unanswered

getting two records on using OnINSERTING table event handler in d365

(0) ShareShare
ReportReport
Posted on by 1,836

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;
    }

I have the same question (0)
  • Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    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.

  • Dineshkarlekar Profile Picture
    1,836 on at

    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
    239,040 Most Valuable Professional on at

    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
    1,836 on at

    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.

  • Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at

    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
    1,836 on at

    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.

  • Dineshkarlekar Profile Picture
    1,836 on at

    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 .

  • Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    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
    1,836 on at

    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.

  • Dineshkarlekar Profile Picture
    1,836 on at

    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.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 658

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 468 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 333 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans