Doesn't update the value on the screen

278 Views Asked by At

I use this code for get the new value for the product, but i want to see this one on the screen, i used:

”row.UnitPrice”, but the data is there, but no on the screen. So i need to call some another funtion for update it?

protected void SOLine_InventoryID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
    {

        var row = (SOLine)e.Row;

        row.UnitPrice = null;

        if (row.OrderType == "SO")
        {
            if (row.InventoryID != null)
            {
                InventoryItem oItem = PXSelect<InventoryItem,Where<InventoryItem.inventoryID,Equal<Required<InventoryItem.inventoryID>>>>.Select(new PXGraph(), row.InventoryID);

                if (oItem != null)
                {
                    decimal? qty = row.Qty;
                    row.UnitPrice = CalcLinePrice( oItem.RecPrice,qty);

                    Base.Transactions.Update(row);

                }
            }
        }

    }

protected decimal? CalcLinePrice(decimal? unitPrice, decimal? qty) 
{
        return unitPrice *2 * (qty);
}
2

There are 2 best solutions below

0
RuslanDev On BEST ANSWER

Agree with Hybridzz: you should update CuryUnitPrice field instead of UnitPrice. Also it's necessary to use PXCache.SetValueExt method to raise all field-level handlers for the CuryUnitPrice field when assigning new value:

sender.SetValueExt<SOLine.curyUnitPrice>(e.Row, price);

On a side note:

  1. you should never invoke Update method for currently processed record in FieldUpdated handlers - Base.Transactions.Update(row); must go away

  2. static PXSelectorAttribute.Select method must be used to retrieve InventoryItem selected for SOLine record:

    • the PXSelectorAttribute stores records in single GlobalCache storage shared among all user sessions: it's a more efficient option in comparison to QueryCache of the PXView class accessible only for 1 user
    • reduce maintenance costs as you don't need to update BQL queries in multiple places if someone change BQL query for the SOLine.InventoryItem field
0
Sin On

The 'Unit Price' column in the Details grid is associated with the field CuryUnitPrice and not the UnitPrice.

So you might need to update the correct DAC field.

row.CuryUnitPrice = CalcLinePrice( oItem.RecPrice,qty);