我试图在持久化逻辑中添加一条新记录到网格中。然而,尽管在用户界面中记录确实被添加到了网格中,但当页面被刷新时,新的行就消失了。它没有被持久化到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);
}
}
类似这样的事情,我倾向于覆盖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();
}