Skip to main content

Hello All,

 

I am trying to override a DAC field “get” method. below is the original DAC field declaration:

#region AmountToComplete
public abstract class amountToComplete : PX.Data.BQL.BqlDecimal.Field<amountToComplete> { }
bPXBaseCury()]
bPXDefault(TypeCode.Decimal, "0.0", PersistingCheck = PXPersistingCheck.Nothing)]
bPXUIField(DisplayName = "Cost To Complete", Enabled = false)]
public virtual Decimal? AmountToComplete
{
rPXDependsOnFields(typeof(budgetedAmount), typeof(completedAmount))]
get { return Math.Max(0, BudgetedAmount.GetValueOrDefault() - CompletedAmount.GetValueOrDefault()); }
}
#endregion

 and I want to completely override it so below is what I have put in my DAC Ext:

#region AmountToComplete
public abstract class amountToComplete : PX.Data.BQL.BqlDecimal.Field<amountToComplete> { }
protected Decimal? _AmountToComplete;
public Decimal? AmountToComplete
{
get { return Math.Max(0, this._UsrHCLForecastToComplete); }
}
#endregion

With my above override, I would expect the original code not be executed and I get the “Math.Max(0, this._UsrHCLForecastToComplete)” but when I trace, the platform executes the original codes and returns the value as per the original formula. I am running on 21R2 and the DAC is a normal BQL table.

Any help is appreciated.

Circulating to the top of the list


When you override a DAC field "get" method, you need to set the value of the field in the override method instead of returning the value. You should also change the "get" accessor to "protected" so that it is not accessible from outside the DAC extension class.

Here's an example of how you can override the "AmountToComplete" field:

#region AmountToComplete
public abstract class amountToComplete : PX.Data.BQL.BqlDecimal.Field<amountToComplete> { }
[PXMergeAttributes(Method = MergeMethod.Replace)]
[PXBaseCury()]
[PXUnboundDefault(TypeCode.Decimal, "0.00", PersistingCheck = PXPersistingCheck.Nothing)]
[PXUIField(DisplayName = "Cost To Complete", Visibility = PXUIVisibility.SelectorVisible, Required = false, Enabled = false, Visible = false)]
protected Decimal? _AmountToComplete;
public Decimal? AmountToComplete
{
get { return _AmountToComplete; }
set { _AmountToComplete = Math.Max(0, this._UsrHCLForecastToComplete); }
}
#endregion

By doing this, the platform will use the value you set in the "set" accessor instead of executing the original code in the "get" accessor.


Reply