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
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.
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();
}
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).