Skip to main content

Notifications

Community site session details

Community site session details

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

X++: Cannot insert multiple records in table. The insert_recordset operation cannot be performed due to an internal error.

(0) ShareShare
ReportReport
Posted on by

Description:

i create a test case, need to use insert_recordset statement to insert record which include utcdatetime field, sometime the test case can run passed, but sometime it will failed due to the error: Cannot insert multiple records in table. The insert_recordset operation cannot be performed due to an internal error. it is unstable .the tables and  test code are very simple, only insert one record to on table, and use insert_recordset to insert to another table, so please give me some suggestions , Thanks!  (PS: only can use insert_recordset , because we want to test the insert_recordset statements)

  • Liya Cheng Profile Picture
    on at
    RE: X++: Cannot insert multiple records in table. The insert_recordset operation cannot be performed due to an internal error.

    yeah,  at present , i don't have  good solution to resolve it. because i cannot repro it. the error was reported in Cloud Test. and it is a random issue. i also try to debug, but still cannot find any useful info.  and based on random issue , NiKolaos suggested that i change the insert_recordset to while select statement. i will continue to check the code, if there is no good solution, i will consider it.

    It is better to delete data before the test than after the test, i will change it, but except it, do you have other suggestion to improve it? please tell me , Thanks!

  • Martin Dráb Profile Picture
    233,675 Most Valuable Professional on at
    RE: X++: Cannot insert multiple records in table. The insert_recordset operation cannot be performed due to an internal error.

    You marked verified answers, but what you said doesn't sound like you have a working solution. Could you clarify your situation, please?

    Also, please use Insert > Insert Code (in the rich-formatting view) to paste source code. Here is the result:

    class TimezoneIDFieldTest extends SysTestCase
    {
    	SRV_View_viewSystemField systemFieldTable;
    	public void setUp()
    	{
    		ttsbegin;
    		// Prepare data.
    		systemFieldTable.Field1 = "Field1";
    		systemFieldTable.insert();
    		ttscommit;
    	}
    	public void tearDown()
    	{
    		TimezoneIDFieldTestTable tzidTable;
    		ttsbegin;
    		// delete data
    		delete_from systemFieldTable;
    		delete_from tzidTable;
    		ttscommit;
    	}
    	
    	[SysTestCheckInTest]
    	public void testTZIDFieldInInsertRecordSetOperation()
    	{
    		// Arrange.
    		TimezoneIDFieldTestTable tzidTable;
    		SRV_View_viewSystemField localSystemField;
    		
    		// Execute.
    		tzidTable.selectForUpdate(true);
    		ttsbegin;
    		
    		// In set based operations, TZID fields will be added to sql query automatically if there is a DateTime field exist.
    		insert_recordset tzidTable(CopyCreatedDateTime, CopyModifiedDateTime, StrField)
    			   select CreatedDateTime, ModifiedDateTime, Field1
    			   from localSystemField;
    		ttscommit;
    		
    		// Assert.
    		int recordCount = 0;
    		while select tzidTable where tzidTable.RecId != 0
    		{
    		   recordCount  ;
    		}
    		this.assertEquals(1, recordCount, "There should only one record exist in TimezoneIDFieldTestTable.");
    		select StrField from tzidTable
    			where tzidTable.CopyCreatedDateTime == systemFieldTable.CreatedDateTime &&
    			tzidTable.CopyModifiedDateTime == systemFieldTable.ModifiedDateTime;
    		this.assertEquals(systemFieldTable.Field1, tzidTable.StrField, "Inserted incorrect record through insert_recordset operation.");
    	}
    }

    By the way, let me simplify it a little bit:

    class TimezoneIDFieldTest extends SysTestCase
    {
    	SRV_View_viewSystemField systemFieldTable;
    	
    	public void setUp()
    	{
    		// Prepare data.
    		systemFieldTable.Field1 = "Field1";
    		systemFieldTable.insert();
    	}
    	
    	public void tearDown()
    	{
    		TimezoneIDFieldTestTable tzidTable;
    		
    		// delete data
    		delete_from systemFieldTable;
    		delete_from tzidTable;
    	}
    	
    	[SysTestCheckInTest]
    	public void testTZIDFieldInInsertRecordSetOperation()
    	{
    		TimezoneIDFieldTestTable tzidTable;
    		SRV_View_viewSystemField localSystemField;
    		
    		// Execute.
    		// In set based operations, TZID fields will be added to sql query automatically if there is a DateTime field exist.
    		insert_recordset tzidTable(CopyCreatedDateTime, CopyModifiedDateTime, StrField)
    			select CreatedDateTime, ModifiedDateTime, Field1
    			from localSystemField;
    		
    		// Assert.
    		select count(RecId) from tzidTable
    			where tzidTable.RecId != 0
    		int64 recordCount = tzidTable.RecId;
    		
    		this.assertEquals(1, recordCount, "There should only one record exist in TimezoneIDFieldTestTable.");
    		
    		select StrField from tzidTable
    			where tzidTable.CopyCreatedDateTime == systemFieldTable.CreatedDateTime
    			   && tzidTable.CopyModifiedDateTime == systemFieldTable.ModifiedDateTime;
    			   
    		this.assertEquals(systemFieldTable.Field1, tzidTable.StrField, "Inserted incorrect record through insert_recordset operation.");
    	}
    }

    To be sure that no record exist in those tables, delete the data before the test, not after.

  • Liya Cheng Profile Picture
    on at
    RE: X++: Cannot insert multiple records in table. The insert_recordset operation cannot be performed due to an internal error.

    ok, i will consider. Thanks!

  • Verified answer
    nmaenpaa Profile Picture
    101,158 Moderator on at
    RE: X++: Cannot insert multiple records in table. The insert_recordset operation cannot be performed due to an internal error.

    Yep.

  • Liya Cheng Profile Picture
    on at
    RE: X++: Cannot insert multiple records in table. The insert_recordset operation cannot be performed due to an internal error.

    your meaning is that we use the following  code to replace the above insert_recordset statement.  and check if it failed in the further?

           while select localSystemField

           {

               tzidTable.CopyCreatedDateTime = localSystemField.CreatedDateTime;

               tzidTable.CopyModifiedDateTime = localSystemField.ModifiedDateTime;

               tzidTable.StrField = localSystemField.Field1;

               tzidTable.insert();

           }

  • Verified answer
    nmaenpaa Profile Picture
    101,158 Moderator on at
    RE: X++: Cannot insert multiple records in table. The insert_recordset operation cannot be performed due to an internal error.

    If it happens only randomly, could you possibly reconsider my suggestion to change the insert_recordSet into a while statement temporarily, and wait if you get a more meaningful error?

    Or, add a second test case that uses a while statement - this way you will see if both of them fail at the same time.

  • Liya Cheng Profile Picture
    on at
    RE: X++: Cannot insert multiple records in table. The insert_recordset operation cannot be performed due to an internal error.

    Attached the actual code, sometime the random error will be thrown when execute insert_recordset statement,

    Note: the error is a random error. cannot be reproduced steadily. i want to improve test case to optimize it.

    class TimezoneIDFieldTest extends SysTestCase

    {

       SRV_View_viewSystemField systemFieldTable;

       public void setUp()

       {

           ttsbegin;

           // Prepare data.

           systemFieldTable.Field1 = "Field1";

           systemFieldTable.insert();

           ttscommit;

       }

       public void tearDown()

       {

           TimezoneIDFieldTestTable tzidTable;

           ttsbegin;

           // delete data

           delete_from systemFieldTable;

           delete_from tzidTable;

           ttscommit;

       }

    [SysTestCheckInTest]

       public void testTZIDFieldInInsertRecordSetOperation()

       {

           // Arrange.

           TimezoneIDFieldTestTable tzidTable;

           SRV_View_viewSystemField localSystemField;

           // Execute.

           tzidTable.selectForUpdate(true);

           ttsbegin;

           // In set based operations, TZID fields will be added to sql query automatically if there is a DateTime field exist.

           insert_recordset tzidTable(CopyCreatedDateTime, CopyModifiedDateTime, StrField)

                   select CreatedDateTime, ModifiedDateTime, Field1

                   from localSystemField;

           ttscommit;

           // Assert.

           int recordCount = 0;

           while select tzidTable where tzidTable.RecId != 0

           {

               recordCount++;

           }

           this.assertEquals(1, recordCount, "There should only one record exist in TimezoneIDFieldTestTable.");

           select StrField from tzidTable

               where tzidTable.CopyCreatedDateTime == systemFieldTable.CreatedDateTime &&

               tzidTable.CopyModifiedDateTime == systemFieldTable.ModifiedDateTime;

           this.assertEquals(systemFieldTable.Field1, tzidTable.StrField, "Inserted incorrect record through insert_recordset operation.");

       }

    }

  • nmaenpaa Profile Picture
    101,158 Moderator on at
    RE: X++: Cannot insert multiple records in table. The insert_recordset operation cannot be performed due to an internal error.

    The code that you shared inserts one record in Table1 (setUp() method).

    We don't see any code that would insert records in Table2, so we don't know what's there when testMethod() is executed.

    Or, at least the variable name is table1. On the other hand, it's not introduced in that method so I think your code will not even compile. Perhaps you can share your actual code with us? Otherwise we might point out mistakes that don't exist in your real code, and not see possible mistakes in your real code.

  • Liya Cheng Profile Picture
    on at
    RE: X++: Cannot insert multiple records in table. The insert_recordset operation cannot be performed due to an internal error.

    Sorry, i don't understand. there is one record in table2, then i use insert_recordset to copy data of table2 to table1, it should insert one record to table1 which is taken from table2. why cannot guarantee? because i cannot find any useful by debugging.  i don't know where it will generate other records to affect the test.

    are there have some ways to avoid the issue?

  • Martin Dráb Profile Picture
    233,675 Most Valuable Professional on at
    RE: X++: Cannot insert multiple records in table. The insert_recordset operation cannot be performed due to an internal error.

    Your code doesn't guarantee in any way that only a single record will be inserted. You're playing with Table1, but the data is taken from Table2.

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 the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

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

#1
Martin Dráb Profile Picture

Martin Dráb 456 Most Valuable Professional

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 310

#3
Saalim Ansari Profile Picture

Saalim Ansari 261

Overall leaderboard

Product updates

Dynamics 365 release plans