【问题标题】:How to Update/Insert/Delete CrossCompany如何更新/插入/删除 CrossCompany
【发布时间】:2016-02-12 01:07:42
【问题描述】:

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

我错过了什么吗?

【问题讨论】:

    标签: axapta x++ dynamics-ax-2012-r2


    【解决方案1】:

    您不能使用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;
        }
    }
    

    【讨论】:

    • 几秒后,我找到了解决办法,如你所愿,谢谢,有帮助
    • 你好,我有一个类似的案例,请你检查并帮助..提前谢谢@MaxPinto 这里是链接stackoverflow.com/questions/56323820/…
    猜你喜欢
    • 1970-01-01
    • 2014-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-11
    相关资源
    最近更新 更多