How to Update/Insert/Delete CrossCompany

南楼画角 提交于 2019-12-13 19:13:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!