Skip to main content
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
  • 286 views

Forum|alt.badge.img+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

Best answer by dbrown23

@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

View original
Did this topic help you find an answer to your question?

3 replies

Forum|alt.badge.img+1
  • Author
  • Semi-Pro I
  • 132 replies
  • September 1, 2022

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


Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • 2624 replies
  • November 1, 2022

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


  • Freshman II
  • 1 reply
  • Answer
  • November 1, 2022

@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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings