Skip to main content

Hello 

I want to set the avg  field value with a desired value as seen in the below screen.
But It is being applied.  

 

I am handling it on FieldUpdated.t

Code Example:

        protected void _(Events.FieldUpdated<INItemSite, INItemSite.inventoryID> e)
        {          

            if (e.Row.InventoryID != null)
            {
                ………….
                    e.Row.AvgCost = (decimal?)100.00;
            }
        }

 




The problem is Avg Cost field is having the PXDBPriceCostCalced attribute , therefore its not setting my desired value.

public abstract class avgCost : PX.Data.BQL.BqlDecimal.Field<avgCost> { }protected Decimal? _AvgCost;aPXPriceCost()]mPXDefault(TypeCode.Decimal, "0.0")]dPXUIField(DisplayName = "Average Cost", Enabled = false)]iPXDBPriceCostCalced(typeof(Switch<Case<Where<INItemStats.qtyOnHand, Equal<decimal0>>, decimal0>, Div<INItemStats.totalCost, INItemStats.qtyOnHand>>), typeof(Decimal), CastToScale = 9, CastToPrecision = 25)]HCurySymbol(siteID: typeof(siteID))]public virtual Decimal? AvgCost{	get	{		return this._AvgCost;	}	set	{		this._AvgCost = value;	}}

 

Any suggestion, on how can I set my avg cost value , with a desired value.

Hi @vramkrishna26,

As you have mentioned, the value is set in PXDBPriceCostCalced attribute, so you can remove the attribute in the CacheAttached and set the field value in the RowSelected.

As the field is not a bound field, you can set in on the go in the RowSelected. Below is an example you can try,

  public class INItemSiteMaint_Extension : PXGraphExtension<PX.Objects.IN.INItemSiteMaint>
{
#region Event Handlers
PXPriceCost()]
PXDefault(TypeCode.Decimal, "0.0")]
PXUIField(DisplayName = "Average Cost", Enabled = false)]
///PXDBPriceCostCalced(typeof(Switch<Case<Where<INItemStats.qtyOnHand, Equal<decimal0>>, decimal0>, Div<INItemStats.totalCost, INItemStats.qtyOnHand>>), typeof(Decimal), CastToScale = 9, CastToPrecision = 25)]
CurySymbol(siteID: typeof(INItemSite.siteID))]
protected virtual void INItemSite_AvgCost_CacheAttached(PXCache cache)
{

}
protected void INItemSite_RowSelected(PXCache cache, PXRowSelectedEventArgs e, PXRowSelected baseHandler)
{
baseHandler?.Invoke(cache, e);
var row = (INItemSite)e.Row;
if (row == null) return;

Base.itemsitesettings.Current.AvgCost = (decimal?)210.00;

}
#endregion
}

 

I am not aware of your requirement but I hope that helps. Thanks,


Reply