问题
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?
回答1:
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;
}
}
来源:https://stackoverflow.com/questions/35353085/how-to-update-insert-delete-crosscompany