【问题标题】:How a customized DB field is saved to DB with in the graph-Acumatica如何将自定义 DB 字段保存到图形中的 DB-Acumatica
【发布时间】:2019-11-13 09:59:51
【问题描述】:

假设POLine 有一个UsrCustomfield,并且还有一些计算来根据同一POLine 中的其他字段填充UsrCustomfield 的值。

哪些事件处理程序用于填充值并将其保存到数据库?必须从 Graph 本身进行保存...但是从哪里来?

【问题讨论】:

  • 您能否提供有关您现有实施的更多信息?
  • 为了更精确和任何要求........在项目屏幕的 CostBudget 选项卡中已经存在一个名为 CostToComplete 的字段。 CostToComplete 中的值为 0。要求是根据某些条件和逻辑填充此字段,而 PXforumula 无法完成......因此,我应该使用哪个事件处理程序在图中填充并保存到 DB

标签: database save acumatica


【解决方案1】:

您有多种方法来计算自定义字段的值。

第一种方法是使用 PXFormula 属性。如果您有一个简单的查询来计算字段的值,这可以很好地工作。这将在 POLine 的 DAC 扩展上设置,您将 UsrCustomfield 声明为属性。帮助文章有许多不同的方法来实现这一点。

https://help-2018r1.acumatica.com/Wiki/(W(59936))/ShowWiki.aspx?pageid=1d25dc74-747c-4d44-8ad9-033e5a476b6f

实现此目的的另一种方法是根据字段或行更新触发事件以重新计算。例如,如果您想在每次使用 ANY 字段更新行时重新计算,您可以使用函数:

public virtual void POLine_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e, PXRowUpdated del)
{
    //first, invoke the base method. can be placed anywhere in your code.
    del?.Invoke(sender, e);

    //get the row
    POLine line = (POLine)e.Row;
    if (line == null) return; //always good to check if the object is not null
    //get the DAC extension from the object
    POLineExt lineExt = line.GetExtension<POLineExt>();
    decimal? CalculatedValue = 0;
    //do some calculation to figure out what the value should be

    //compare the new value against the existing value
    if(lineExt.UsrCustomField != CalculatedValue)
    {
        //set the new value
        sender.SetValueExt<POLineExt.usrCustomField>(line, CalculatedValue);
    }            
}

这个问题是每次更新 POLine 时都会调用代码。这可能是太多的调用。您也可以使用函数来更新每个单独的行,使用每个字段上的 FieldUpdated 事件来重新计算。例如,您可能想要检查 ExtCost:

public virtual void POLine_ExtCost_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e, PXFieldUpdated del)
{
    //similar code as above            
}

此方法代码更多,也更复杂,但如果您的逻辑无法适应 PXFormula 属性,则可能需要此方法。

【讨论】:

  • 感谢您回复 KRichardson,
  • 感谢 KRichardson 的回复。 Rowupdated 事件根本没有触发我正在使用此事件 protected void PMCostBudget_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e) { PMCostBudget row = (PMCostBudget)e.Row; row.CuryCostToComplete = row.CuryActualPlusOpenCommittedAmount;// CuryCostToComplete 是项目屏幕缓存中已有的 DB 字段。SetValueExt(row, row.CuryCostToComplete);另一件事是如何将此字段保存到 DB 而无需在图中执行保存操作。
  • 确保要触发任何更新的字段的 CommitChanges 设置为 True。您是否正在考虑将此字段保存到数据库中是否实际保存所做的更改?数据可能不同步,并且可能会在后端进行更改时导致图表出现问题,从而导致缓存中的记录过时。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多