首页 > 解决方案 > 全局通用字段更新事件

问题描述

我有 50 多个自定义配对字段“英寸”和“厘米”,每个字段都已启用且可编辑。如果用户更改了“厘米”和签证的值,我需要更新“英寸”。在字段更新事件期间,我能够在其中一个配对字段上使用 SetValuePending 并在另一个字段上使用 SetValueExt 来做到这一点。我的问题是,有没有一种方法可以在更高级别上执行此操作,而无需为所有 100 多个字段执行 Field_Updated 事件。我知道公式会创建循环引用,因此无法使用。谢谢

标签: acumatica

解决方案


您可以通过PXFormula+ ExternalValueBQL 表达式(与PXRowUpdatedEventArgs.ExternalCall示例相同)来执行此操作,这将防止对字段之间的循环引用。想法是仅当用户从 UI 更改相关字段时才计算字段(ExternalCall= true),并在公式更新相关字段时跳过计算(ExternalCall= false)。

public class centimetersInInches : PX.Data.BQL.BqlDecimal.Constant<centimetersInInches>
{
    public centimetersInInches() : base(2.54m) { }
}

[PXDecimal]
[PXUIField(DisplayName = "Inches")]
[PXUnboundDefault(TypeCode.Decimal, "0.0")]
[PXFormula(typeof(ExternalValue<Div<centimeters, centimetersInInches>>))]
public virtual decimal? Inches { get; set; }
public abstract class inches : PX.Data.BQL.BqlDecimal.Field<inches> { }

[PXDecimal]
[PXUIField(DisplayName = "Centimeters")]
[PXUnboundDefault(TypeCode.Decimal, "0.0")]
[PXFormula(typeof(ExternalValue<Mult<inches, centimetersInInches>>))]
public virtual decimal? Centimeters { get; set; }
public abstract class centimeters : PX.Data.BQL.BqlDecimal.Field<centimeters> { }

和aspx

<px:PXGridColumn DataField="Inches" CommitChanges="True" />
<px:PXGridColumn DataField="Centimeters" CommitChanges="True" />

推荐阅读