0
votes

I have added a field to the Prepare Replenishment form that needs to be updated when a user selects a row in the Replenishment Item grid. How do I access the field. I know it is in the INReplenishmentFilterExt but I can't figure out how to get access to the extension.

Edit #1: I am able to get the value of the field but it does not update on the screen when I use cache.SetValue. I am trying to update this filter extension field from inside of the Selected event handler.

protected void INReplenishmentItem_Selected_FieldUpdating(PXCache cache, PXFieldUpdatingEventArgs e)
{
    var row = (INReplenishmentItem)e.Row;
    if (row == null)
        return;
    INReplenishmentFilter filter = Base.Filter.Current;
    INReplenishmentFilterExt filterExt = PXCache<INReplenishmentFilter>.GetExtension<INReplenishmentFilterExt>(filter);

    decimal poAmount = filterExt.UsrPOAmount.HasValue ? filterExt.UsrPOAmount.Value : 0;
    decimal lastPrice = pvi.LastPrice.HasValue ? pvi.LastPrice.Value : 0;
    decimal newPOAmount = poAmount + lastPrice;

    cache.SetValue<INReplenishmentFilterExt.usrPOAmount>(filterExt, newPOAmount);
}
1

1 Answers

0
votes

You cannot set the value of the Filter using the Cache of INReplenishmentItem. I have edited my answer, the code below should work.

//Always use virtual methods for Event Handlers
protected virtual void INReplenishmentItem_Selected_FieldUpdating(PXCache sender, PXFieldUpdatingEventArgs e)
{
    //Try not to use vars. Especially when you know the Type of the object
    INReplenishmentItem row = e.Row as INReplenishmentItem;

    if (row != null)
    {
        INReplenishmentFilter filter = Base.Filter.Current;
        INReplenishmentFilterExt filterExt = PXCache<INReplenishmentFilter>.GetExtension<INReplenishmentFilterExt>(filter);

        decimal poAmount = filterExt.UsrPOAmount ?? 0;
        decimal lastPrice = pvi.LastPrice ?? 0;//Not sure what pvi is
        decimal newPOAmount = poAmount + lastPrice;

        //"sender" is the cache that specifically stores the datatype of row
        //Therefor you cannot use it to update records of a different datatype
        //You also should not pass an Extension into the argument that should be the row object you are trying to update
        Base.Filter.Cache.SetValueExt<INReplenishmentFilterExt.usrPOAmount>(filter, newPOAmount);
    }
}