首页 > 解决方案 > 保存记录时插入网格线

问题描述

我正在尝试在持久逻辑期间将新记录添加到网格中。但是,即使记录确实添加到 UI 中的网格中,当页面刷新时,新行也会消失。它没有在数据库中持久化。

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

代码示例

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

保存后的结果 - 记录显示在网格中: 在此处输入图像描述

取消后的结果 - 记录从网格中消失: 在此处输入图像描述

标签: acumatica

解决方案


像这样的事情,我倾向于在调用 base persist 之前覆盖 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();
}

推荐阅读