Skip to main content
Answer

How to override the get return value in DAC Ext.

  • January 8, 2023
  • 2 replies
  • 408 views

aaghaei
Captain II
Forum|alt.badge.img+10

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> { }
[PXBaseCury()]
[PXDefault(TypeCode.Decimal, "0.0", PersistingCheck = PXPersistingCheck.Nothing)]
[PXUIField(DisplayName = "Cost To Complete", Enabled = false)]
public virtual Decimal? AmountToComplete
{
[PXDependsOnFields(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;
[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)]
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.

Best answer by Yuriy Zaletskyy

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.

2 replies

aaghaei
Captain II
Forum|alt.badge.img+10
  • Author
  • Captain II
  • January 11, 2023

Circulating to the top of the list


Yuriy Zaletskyy
Jr Varsity I
Forum|alt.badge.img+3

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.