Wednesday, May 20, 2020

Update Recordset for Updating other company records by Crosscompany in Ax 2012

Update Recordset by crossCompany

  while select BB_CompanyId from bB_RippleTable where bB_RippleTable.BB_PriceExpiration ==            NoYes::Yes
    {
      // You must disable update method, database log and alerts, otherwise compiler will throw an    error, for example:
        inventTable.skipDataMethods(true);
        inventTable.skipDatabaseLog(true);
        inventTable.skipEvents(true);
        update_recordSet crossCompany inventTable
        setting RepairFee_BB = 100
        where inventTable.ItemId == "fit123"
        && inventTable.dataAreaId == bB_RippleTable.BB_CompanyId;
     
        info('done');
    }

///note : some time it will not work for all users the user must have admin rights to do, so in that
// case we doing in different way as below

   while select CompanyId from bB_RippleTable where bB_RippleTable.PriceExpiration == NoYes::Yes
    {
        changeCompany(bB_RippleTable.CompanyId)
        {
            ttsBegin;
            inventTableModule = null;
            select forUpdate inventTableModule
                where inventTableModule.ItemId == _itemid
                && inventTableModule.ModuleType == ModuleInventPurchSales::Purch
                && inventTableModule.dataAreaId == bB_RippleTable.CompanyId;

            if(inventTableModule.RecId != 0)
            {
                inventTableModule.PriceExpirationDate_BB = _date;
                inventTableModule.update();
                info(strFmt("@BBX5747",inventTableModule.PriceExpirationDate_BB,bB_RippleTable.CompanyId));
            }
            ttscommit;
        }
    }

No comments:

Post a Comment