如何 Update/Insert/Delete 跨公司

How to Update/Insert/Delete CrossCompany

是否可以在 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;
}

我有一个try catch,调试,在方法tlRemoteLocationInfo.update()中更新失败,异常是:

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

我是不是漏了什么?

您不能使用 crossCompany 关键字进行更新操作。看这里: https://msdn.microsoft.com/en-us/library/cc518738.aspx

我重写了您的代码,使其正常运行。如果这是 CIL 中的 运行,请确保进行增量 CIL 编译。第二种方法是如果你想做一会儿-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;
    }
}