Insert a grid line when the record gets saved

南笙酒味 提交于 2020-06-17 06:30:09

问题


I am trying to add a new record to a grid during the persist logic. However, even though the record does get added to the grid in the UI, when the page gets refreshed, the new line disappears. It is not getting persisted in the DB.

I am using the Bills page as reference.

Code sample

protected virtual void APTran_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
{
    if (e.Row == null)
    {
        return;
    }

    APInvoice invoiceRow = this.Base.Document.Current;

    if (invoiceRow != null)
    {

        APTran tranRow = new APTran();
        tranRow = this.Base.Transactions.Insert(tranRow);

        tranRow.InventoryID = 10043;
        this.Base.Transactions.Update(tranRow);

        tranRow.Qty = 3;
        this.Base.Transactions.Update(tranRow);
    }
}

Result after saving - Record is shown in the grid:

Result after cancelling - Record disappears from the grid:


回答1:


Something like this I tend to override the Persist method and insert or update related records before calling base persist. Here is a possible example which goes inside your graph extension:

[PXOverride]
public virtual void Persist(Action del)
{
    foreach(APInvoice invoiceRow in Base.Document.Cache.Inserted)
    {
        APTran tranRow = this.Base.Transactions.Insert();

        tranRow.InventoryID = 10043;
        tranRow = this.Base.Transactions.Update(tranRow);

        tranRow.Qty = 3;
        this.Base.Transactions.Update(tranRow);
    }

    del?.Invoke();
}


来源:https://stackoverflow.com/questions/61870001/insert-a-grid-line-when-the-record-gets-saved

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!