Alfasith AX

Alfasith AX
اللَّهُمَّ انْفَعْنِي بِمَا عَلَّمْتَنِي، وَعَلِّمْنِي مَا يَنْفَعُنِي، وَزِدْنِي عِلْمًا

Sunday, May 25, 2014

insert_recordset in dynamic AX - Insert all the records to duplicate table.

Hi,

Normally we used to insert the record like below to transfer the record from 1 table to another.

SourceTableName SourceTbl;
DestinationTableName DestinationTbl;
int records;
ttsBegin;
while select * from SourceTbl
    where SourceTbl.tabId > 0
{
    DestinationTbl.Field1        = SourceTbl.Field1;
    DestinationTbl.Field2       = SourceTbl.Field2;
    DestinationTbl.Field3        = SourceTbl.Field3;
    //So on fields... but it should n=match with datatype / EDT /Enum
    DestinationTbl.insert();
    records++;
}
ttsCommit;
info(records);
/********************************************/
but AX there is another feature to insert the bulk of record without transmission delay in reduced set of codes.

Same above code is reduced to.

insert_recordset DestinationTbl 
    select SourceTbl
         // where SourceTbl.Feild1 <= 100 
// If you have any condition to filter else al the record will be transfer
 /*****************************************************/
If you want to map the fields you need to.
insert_recordset DestinationTbl (Feild1, Feild2, Feild3...)
    select Feild1, Feild2, Feild3... 
        from SourceTbl
            where SourceTbl.Feild1 <= 100; //if condition 

Regards,




1 comment:

How find size of recordsortedlist in D365/AX 2012

Hi, This is the continuity of the previous article where we are now getting the size of recordsortedlist . if(recordsortedlist.len() >1) ...