保存记录时插入一条网格线

问题描述 投票:1回答:1

我试图在持久化逻辑中添加一条新记录到网格中。然而,尽管在用户界面中记录确实被添加到了网格中,但当页面被刷新时,新的行就消失了。它没有被持久化到DB中。

我使用了 账单 页面作为参考。

代码示例

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

保存后的结果 - 记录显示在网格中。enter image description here

取消后的结果 - 记录从网格中消失。enter image description here

acumatica
1个回答
1
投票

类似这样的事情,我倾向于覆盖Persist方法,在调用base persist之前插入或更新相关记录。这里有一个可能的例子,它可以在你的图形扩展中使用。

[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();
}
© www.soinside.com 2019 - 2024. All rights reserved.