Acumatica-复制最后一行 [英] Acumatica - Copy last row

查看:82
本文介绍了Acumatica-复制最后一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,看起来Acumatica中看似简单的事情实现起来非常复杂。我要做的就是将网格的最后一行复制为新网格。我希望用户自己保留更改,因此我的代码会将其保存在缓存中。到目前为止,这是我的操作:

So looks like seemingly easy things in Acumatica are terribly complicated to implement. All I wanna do is to copy last row of my grid as a new one. I would like the user to persist the changes himself, so my code would put it just in cache. This is my action so far:

    public PXAction<SOOrder> copyLastRow;
    [PXUIField(DisplayName = "Copy Last Row", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
    [PXLookupButton]
    public virtual IEnumerable CopyLastRow(PXAdapter adapter)
    {
        SOLine line = Base.Transactions.Select().LastOrDefault();
        int? lineNbr = 0;

        foreach(SOLine line2 in Base.Transactions.Select())            
            if (line2.LineNbr > lineNbr)
                lineNbr = line2.LineNbr;



        line.LineNbr = lineNbr + 1;
        Base.Transactions.Cache.Insert(line);           

        return adapter.Get();
    }

所以也许我的代码没有出现错误或完全错误,但是我无论我做什么,都会出错。我的行没有刷新网格,并且我不断收到各种错误,例如无法保存此记录或另一个进程更新了此记录等。此外,关于如何生成新lineNbr的任何想法我有笨拙的逻辑?

So maybe I am not getting something or completely wrong in my code, but I'm getting errors no matter what I do. The grid is not getting refreshed with my row and I keep getting all sorts of errors, such as "This record cannot be saved" or "another process updated this record", etc. Also, any ideas on how to generate a new lineNbr without clunky logic I have? Much appreciated if anyone can help.

推荐答案

如果只想一行并复制所有值,则可以使用缓存复制和空行号。然后在插入复制的行时,它将自动获得下一个linenbr ...在您的问题中添加到示例代码中。

If you just want to take the line and copy all values you can use cache copy and null the lineid. Then on insert of the copied line it will get the next linenbr automatically... adding to your sample code in your question...

SOLine line = Base.Transactions.Select().LastOrDefault();
var copy = (SOLine)Base.Transactions.Cache.CreateCopy(line);
copy.LineNbr = null;
Base.Transactions.Cache.Insert(copy);

如果在SOLine中添加了新字段或自定义项,则此方法也应该易于升级复制而不必选择性地包括要复制的所有字段(使用CreateCopy)。

This method should also be upgrade friendly in the event new fields or customization are added to SOLine they will continue to be copied without having to selectively include all fields to be copied (using CreateCopy).

这篇关于Acumatica-复制最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆