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, ...
Suggested Answer

Insert Recordset and If statement

(0) ShareShare
ReportReport
Posted on by 10
Hi, I would like to change isnert statement to insert_recordset in if statement.
 
Here is the sample code.
 
MyTable.Field1 = Value1
MyTable.Field2 = Value2
If (A=B)
{
   MyTable.Field3 = Value3
}
Select firstonly InvoiceType
If (InvoiceType)
{
     MyTable.Field4 = '0'
}
MyTable.Field5 = Value5
MyTable.insert();
 
How to change this code with insert_recordset??
 
 
 
 
 
 
 
I have the same question (0)
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,801 Super User 2026 Season 1 on at
    Hi,
     
    I think you can use RecordInsertList 
     
     
    Best regards,
    Mohamed Amine MAHMOUDI
  • Community member Profile Picture
    10 on at
    Thank you for suggesting the answer. 
    I read the article but I did not get it completely.
     
    Could you rewrite my code with RecordInsertList ?
     
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,801 Super User 2026 Season 1 on at
    Hi,
     
    e.g.
     
    MyTable           MyTable;
    SourceTable       sourceTable;
    RecordInsertList  myList;
    
    myList = new RecordInsertList(tableNum(MyTable)); 
    
    while select sourceTable where ...
    {
       MyTable.clear();
       MyTable.Field1 = sourceTable.Value1;
       MyTable.Field2 = sourceTable.Value2;
       If (sourceTable.A=sourceTable.B)
       {
          MyTable.Field3 = sourceTable.Value3;
       }
       Select firstonly InvoiceType;
       If (InvoiceType)
       {
          MyTable.Field4 = '0';
       }
       MyTable.Field5 = sourceTable.Value5;
       myList.add(MyTable);
    }
    myList.insertDatabase();
    Best regards,
    Mohamed Amine MAHMOUDI
  • Suggested answer
    Community member Profile Picture
    10 on at
    Thank you for answering my question. I undestand that how to use RecordinsertList in general.
     
    I still need to get support for the code below.
    I think I can join the tableB and tableC, but I am really appreciate if you can rewrite the code again.
    Thank you for in advance.
     
     
     
    SourcetableA TableA;
    SourcetableB TableB;
    SourcetableC TableC;
    str text;
     
    MyTable.Field1 = Value1
    MyTable.Field2 = Value2
    If (TableA.A = TableA.B)
    {
       MyTable.Field3 = Value3
    }
    Select firstonly crosscompany InvoiceType
    where InvoiceType.Filed4 = TableA.Field4
     
    If (InvoiceType)
    {
         MyTable.Field5 = '0'
    }
     
    while select crosscompany TableC
    order by InvoiceNumber asc
    where TableC.Field6 = TableA.Field6
     {
                    text+= strFmt('%1/',TableC.text);
    }
    text= subStr(subStr(text, 1, strLen(text) -1),1,155);
    MyTable.text= text;
     
    MyTable.insert();
     
     
  • Martin Dráb Profile Picture
    239,022 Most Valuable Professional on at
    Your latest code doesn't make a good sense. You use fields of TableA (e.g. A or Field4), but they'll always be empty, because you've never set any value to tableA variable.
     
    On the other hand, you've declared TableB but never used it for anything.
     
     
     
  • Layan Jwei Profile Picture
    8,165 Super User 2026 Season 1 on at
    Hi Community member,

    Insert_recordset is used to copy data from one table to another. You can check this link for more details about it
    https://learn.microsoft.com/en-us/dynamicsax-2012/developer/insert-recordset

    However, as Mohamed said, i think you mean you want to use recordInsertList instead.
     
    Looking at the last code you shared:
    myTable and invoiceType tables  are not declared
    TableB is not used
    TableA and TableC are not selected, so they will always be empty
     
    So i'm not sure what you really mean by "I think I can join the tableB and tableC" if you don't use tableB in the first place and if table C is empty -- so please provide us with the correct code in order to help you.

    Thanks,
    Layan Jweihan
  • Suggested answer
    Community member Profile Picture
    10 on at
    Sorry for the messy.
    Here is the code which I would like to write with RecordInsertList.
     
     
     
    MyTable My Table;
    InvoiceTypeTable InvoiceType;
    SourcetableA TableA; 
    SourcetableB TableB; 
    SourcetableC TableC;
    str text;
     
    MyTable.Field1 = TableA.Value1;
    MyTable.Field2 = TableA.Value2;
     
    Select firstonly crosscompany TableB
    where TableB.Filed3 = TableA.Value3;
     
    If (InvoiceType)
    {
         MyTable.Field3 = '0';
    }
     
    while select crosscompany TableC
    order by TableC.InvoiceNumber asc
    where TableC.Field4 = TableA.Value4
     {
                    text+= strFmt('%1/',TableC.text);
    }
    text= subStr(subStr(text, 1, strLen(text) -1),1,155);
    MyTable.text= text;
    MyTable.Field5 = TableA.Value5;
     
    MyTable.insert();
  • Martin Dráb Profile Picture
    239,022 Most Valuable Professional on at
    You marked your last reply as a suggested answer, but it doesn't seem to contain any solution for this thread. Please don't use it unless you're providing a possible solution.
     
    Unfortunately your code still contains similar bugs. You never populate TableA and InvoiceType variables, therefore they'll always be empty. You also never use the value of TableB. Your code effectively does this:
    SourcetableC tableC;
    str text;
     
    while select crosscompany tableC
        order by tableC.InvoiceNumber asc
        where tableC.Field4 = ''
    {
        text += strFmt('%1/',TableC.text);
    }
    
    text = subStr(subStr(text, 1, strLen(text) -1), 1, 155);
    
    MyTable myTable;
    myTable.Text = text;
    myTable.insert();
     
  • Community member Profile Picture
    10 on at
    Could you please just do only the code that can make sense?
     
    I would like to rewrite with RecordInsertList.
     
    SourcetableC tableC;
    str text;
     
    while select crosscompany tableC
        order by tableC.InvoiceNumber asc
        where tableC.Field4 = ''
    {
        text += strFmt('%1/',TableC.text);
    }
    
    text = subStr(subStr(text, 1, strLen(text) -1), 1, 155);
    
    MyTable myTable;
    myTable.Text = text;
    myTable.insert();
  • Martin Dráb Profile Picture
    239,022 Most Valuable Professional on at
    There is no need for RecordInsertList, because your code inserts a single record.
     
    Note that Mohamed showed you how to use RecordInsertList (and you even replied that you knew how to use it).

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!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 617

#2
André Arnaud de Calavon Profile Picture

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

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 298 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans