AX – D365FO – Using update_recordset with CrossCompany statement

If you have tried to use Update_recordset with CrossCompany option you’ll probably have faced this error : “Cannot update multiple records in yourTable(yourTable).
Cross company update_recordset operation should skip database logging.”

The reason is because you have to disable database logging before to proceed

To solve this issue you must use these methods :

yourTable.skipDataMethods(true);

yourTable.skipDatabaseLog(true);

yourTable.skipEvents(true);

Follow this code :

TaxTrans        taxTrans;
TaxBook         taxBook;
TaxBookSection  taxBookSection;

taxBook = TaxBook::findByTaxBookId('ACQCEE');
taxBookSection = TaxBookSection::findByTaxBookSection('ACQCEE');

if(taxBook && taxBookSection)
{
   ttsbegin;
            
   taxTrans.skipDataMethods(true); //Use these methods to solve the issue
   taxTrans.skipDatabaseLog(true); //Use these methods to solve the issue
   taxTrans.skipEvents(true);      //Use these methods to solve the issue

   update_recordset crossCompany  taxTrans
   setting  TaxBook = taxBook.recId, 
            TaxBookSection = taxBookSection.RecId
   where taxTrans.TaxBook == 0
   &&    taxTrans.Voucher like 'ACEE21*'
   &&    TaxTrans.dataAreaId == 'DAT';
   
   ttscommit;

   info(strFmt(" %1 rows updated", int2Str(taxTrans.RowCount())));

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s