如何更新/插入/删除CrossCompany

Max*_*nto 1 x++ axapta dynamics-ax-2012-r2

是否可以在axapta中插入,更新或删除crossCompany?

我想这样做,在我的查询调试我有这个:

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;
}
Run Code Online (Sandbox Code Playgroud)

我有一个try catch,并且调试,无法在方法tlRemoteLocationInfo.update()中更新,例外是:

$ exception {"Se produjounaexppcióndetipo'Microsoft.Dynamics.Ax.Xpp.ErrorException'."} System.Exception {Microsoft.Dynamics.Ax.Xpp.ErrorException}

我错过了什么?

Ale*_*tny 7

您无法使用crossCompany关键字执行更新操作.请看:https: //msdn.microsoft.com/en-us/library/cc518738.aspx

我重写了你的代码,以便它可以工作.如果在CIL中运行,请确保执行增量CIL编译.第二种方法是如果你想做一个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;
    }
}
Run Code Online (Sandbox Code Playgroud)