Friday, September 14, 2018

AX - How to insert new row based on existing row data in table

This example shows how to duplicate one row data to new row in one table (with update of some values).
static void job_duplicate_row(Args _args)
{
    EmployeeTable_RU tab1, tab2;
         
    tab1 = EmployeeTable_RU::findByEmployeeId( '32' );
    if ( !tab1 ) {
        info( "Source row not found." );
        return;
    }
            
    ttsBegin;
    
    /* copy row data from tab1 to tab2 + change two columns values */

    tab2.data( tab1 );
    tab2.EmployeeId = '463';
    tab2.HcmEmployment = 5637145327;

    if ( !tab2.validateWrite() ) throw Exception::Error;

    tab2.insert();

    ttsCommit;
    
    info( "OK" );
}

No comments:

Post a Comment