1

is possible to make insert, update or delete crossCompany in axapta?

i am trying to do that, debugging in my query i have this:

select forUpdate crossCompany tlRemoteLocationInfo
                where tlRemoteLocationInfo.RemoteLocationId == "someId";
if (tlRemoteLocationInfo.RecId)
{
   ttsBegin;
   changeCompany(tlRemoteLocationInfo.dataAreaId)
   //then i make mi update to fields and then i make this:
   tlRemoteLocationInfo.update();
   ttsCommit;
}

i have a try catch, and debugging, fails to update in the method tlRemoteLocationInfo.update(), the exception is:

$exception {"Se produjo una excepción de tipo 'Microsoft.Dynamics.Ax.Xpp.ErrorException'."} System.Exception {Microsoft.Dynamics.Ax.Xpp.ErrorException}

Am i missing someghing?

Alex Kwitny
  • 11,211
  • 2
  • 49
  • 71
Max Pinto
  • 1,463
  • 3
  • 16
  • 29

1 Answers1

7

You can't do update operations using the crossCompany keyword. See here: https://msdn.microsoft.com/en-us/library/cc518738.aspx

I rewrote your code so that it should work. And make sure to do an incremental CIL compile if this is running in CIL. The second method is if you wanted to do a while-select.

// Rewrite 1 - Notice removal of "forUpdate"
select firstOnly crossCompany tlRemoteLocationInfo
    where tlRemoteLocationInfo.RemoteLocationId == "someId";

if (tlRemoteLocationInfo)
{
    changeCompany(tlRemoteLocationInfo.dataAreaId)
    {
        // Notice this line
        tlRemoteLocationInfo.selectForUpdate(true);
        ttsBegin;
        //then i make mi update to fields and then i make this:
        tlRemoteLocationInfo.update();
        ttsCommit;
    }
}

// Rewrite 2 - Is a "while select" what you want?
while select crossCompany tlRemoteLocationInfo
    where tlRemoteLocationInfo.RemoteLocationId == "someId"
{
    changeCompany(tlRemoteLocationInfo.dataAreaId)
    {
        // Notice this line
        tlRemoteLocationInfo.selectForUpdate(true);
        ttsBegin;
        //then i make mi update to fields and then i make this:
        tlRemoteLocationInfo.update();
        ttsCommit;
    }
}
Alex Kwitny
  • 11,211
  • 2
  • 49
  • 71
  • few seconds later, i found a solution, such as you give, thanks, it helps – Max Pinto Feb 12 '16 at 17:18
  • hello, i have a similar case, would you kindly check and help.. thanks in advance @MaxPinto here is the link https://stackoverflow.com/questions/56323820/alternative-way-of-updating-record-in-x – rickyProgrammer May 28 '19 at 04:14