Solved

Why are my custom field's values resetting to 0 when changing other fields on the screen and saving?

  • 1 September 2022
  • 3 replies
  • 206 views

Userlevel 5
Badge +1

I created some new fields on the Price/Cost tab of the Stock Item screen:

UsrWhlPrice

UsrWhlPriceChangeDate

UsrPrevWhlPrice

UsrPrevWhlPriceChangeDate

 

The intention is that the first will store the wholesale price for an item and the second records any time the wholesale price is changed.

The UsrPrev… fields will be updated when the wholesale price changes.

 

I added them and all appeared to be fine.  I tested and they recorded the information I needed and I used them in an import scenario to import the wholesale prices.

I am using the code below to monitor for a change to the price and update the fields.

    protected void InventoryItemCurySettings_UsrWHLPrice_FieldVerifying(PXCache cache, PXFieldVerifyingEventArgs e, PXFieldVerifying InvokeBaseHandler)
{
if(InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);
var row = (InventoryItemCurySettings)e.Row;

if (row== null) return;

try {
InventoryItemCurySettingsExt inventoryItemCurySettingsExt =
PXCache<InventoryItemCurySettings>.GetExtension<InventoryItemCurySettingsExt >(row);

if (inventoryItemCurySettingsExt.UsrWHLPrice != null) {
inventoryItemCurySettingsExt.UsrPrevWHLPrice = inventoryItemCurySettingsExt.UsrWHLPrice;
}
}
catch (Exception error) {
PXTrace.WriteInformation("Error: " + error);
}
}



// Adds WHL Price and Timestamp fields
protected void InventoryItemCurySettings_UsrWHLPrice_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler)
{
if(InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);
var row = (InventoryItemCurySettings)e.Row;
if (row== null) return;

try {
InventoryItemCurySettingsExt inventoryItemCurySettingsExt =
PXCache<InventoryItemCurySettings>.GetExtension<InventoryItemCurySettingsExt >(row);

if (inventoryItemCurySettingsExt.UsrWhlPriceChangeDate != null) {
inventoryItemCurySettingsExt.UsrPrevWhlPriceChangeDate = inventoryItemCurySettingsExt.UsrWhlPriceChangeDate;
}

inventoryItemCurySettingsExt.UsrWhlPriceChangeDate = PX.Common.PXTimeZoneInfo.Now;
}
catch (Exception error) {
PXTrace.WriteInformation("Error: " + error);
}
}

The problem is that when I change other details on the Stock Items screen and save it is losing the value that was already saved in the field.  Changing the default Vendor did this and also changing the non-wholesale price (Default Price) and clicking save. The value in UsrWhlPrice is reset to 0.00.

What am I dong wrong?

I think I am doing something wrong in this but I don’t know what.

Any help would be very much appreciated,

Phil

icon

Best answer by dbrown23 1 November 2022, 21:02

View original

3 replies

Userlevel 5
Badge +1

After testing this in more depth iand disabling all event handlers I set up it still happens. It appears that it is because the fields are in the ItemCurySettings form on the Price/Cost tab.  If I recreate the fields outside of that they don’t get cleared.  I’m going to recreate them outside as a workaround but I’m still interested to find out why they are being cleared and if it’s possible to stop it happening in future.

 

Phil

Userlevel 7
Badge

Hi @ppowell - were you able to find a solution? Thank you!

@Chris Hackett I gave up and moved the custom fields so they came under InventoryItem instead of InventoryItemCurySettings.  They don’t reset there and work fine for our purposes.  I’d still be interested to hear why they get reset but it’s not a priority any more.

 

Thanks,

 

Phil

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