Acumatica - Copy last row

后端 未结 3 1810
眼角桃花
眼角桃花 2021-01-26 03:59

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 pers

相关标签:
3条回答
  • 2021-01-26 04:46

    It is my guess that Line Number will get automatically generated ! It is not in sequence anyway.

    I suggest you create a new SOline row and transfer the enterable fields from the selected row (Last row) in the same and Insert. Should work.

    0 讨论(0)
  • 2021-01-26 05:02

    The code should be like this:

    public PXAction<SOOrder> copyLastRow;
    [PXUIField(DisplayName = "Copy Last Row", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
    [PXProcessButton]
    public virtual IEnumerable CopyLastRow(PXAdapter adapter)
    {
        SOLine line = Base.Transactions.Select().LastOrDefault();
        SOLine newLine = new SOLine();
        ... (copy all you need from line to newLine)
        Base.Transactions.Cache.Insert(newLine);           
        Base.Actions.PressSave();
        return adapter.Get();
    } 
    
    0 讨论(0)
  • 2021-01-26 05:03

    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);
    

    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).

    0 讨论(0)
提交回复
热议问题