Reputation: 75
I have a custom field to be created which is DB field. Initial value of the "Forecast to Complete" field is null even though default value is 0.0.
How do i get the DB field 0.00 initially?
[PXDBDecimal(2)]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName="Forecast To Complete")]
Upvotes: 0
Views: 301
Reputation: 7706
PXDefaultAttribute
is allowing you to set the default value for new records.
The value is assigned when the record is inserted for the first time.
You can write FieldSelecting event handler and check the value of the field and set to the default one if the value is null
.
Upvotes: 1
Reputation: 8278
Maybe there's a mechanism assigning a null value after the field has been initialized.
If the record is created from UI you can try setting AllowNull
property to False
value:
<px:PXNumberEdit ID="edForecastToComplete" runat="server" AllowNull="False"
DataField="ForecastToComplete" Decimals="4" ValueType="Decimal" />
Worst case scenario you can force the assignation to be non null using C# property setter and backing field:
public decimal? _forecastToComplete;
[PXDBDecimal]
[PXUIField(DisplayName = "Forecast to Complete")]
public virtual decimal? ForecastToComplete
{
get { return _forecastToComplete != null ? _forecastToComplete : 0M; }
set { _forecastToComplete = value != null ? value : 0M }
}
public abstract class forecastToComplete : IBqlField { }
Upvotes: 1