如何在图-Acumatica中将自定义数据库字段保存到数据库

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

哪个事件处理程序用于填充值并将其保存到DB?保存必须从Graph本身完成...但是从哪里开始?

biefanwoxingme 回答:如何在图-Acumatica中将自定义数据库字段保存到数据库

您可以通过多种方式来计算自定义字段的值。

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

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属性,则可能需要此方法。

本文链接:https://www.f2er.com/3111180.html

大家都在问