Solved

How to override the get return value in DAC Ext.

  • 8 January 2023
  • 2 replies
  • 252 views

Userlevel 7
Badge +8

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.

icon

Best answer by Yuriy Zaletskyy 22 January 2023, 11:39

View original

2 replies

Userlevel 7
Badge +8

Circulating to the top of the list

Userlevel 5
Badge +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.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved