Solved

Why does my custom field no longer update after upgrade from 2022R2 to 2023R2?

  • 11 March 2024
  • 6 replies
  • 68 views

Userlevel 5
Badge +1

I have a customization which updates a custom date field when another custom field (called UsrAIWHLPrice) is updated.  This has been working fine since 2022.  Since upgrading to 2023R2 the field doesn’t update any longer. 

 

The code is below:

 

protected void InventoryItem_UsrAIWHLPrice_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler)
{
if(InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);
var row = (InventoryItem)e.Row;

if (row == null) return;

try{

InventoryItemExt invItemExt = PXCache<InventoryItem>.GetExtension<InventoryItemExt>(row);
if (invItemExt.UsrAIWHLPriceChangeDate != null) {
invItemExt.UsrAIWHLPrevPriceChangeDate = invItemExt.UsrAIWHLPriceChangeDate;
}

invItemExt.UsrAIWHLPriceChangeDate = PX.Common.PXTimeZoneInfo.Now;

}
catch (Exception error) {
PXTrace.WriteInformation("error: " + error);
}
}

There is no error in trace so I suspect it is because I haven’t used the correct method to update the field in the extension. I think I should be updating the cache instead but I’m not sure how to do that.

 

Can anyone advise where I’m going wrong?

 

Thanks,

 

Phil

icon

Best answer by darylbowman 11 March 2024, 15:24

View original

6 replies

Userlevel 7
Badge +11

Hi @ppowell ,

Could you please try the below code?

protected void InventoryItem_UsrAIWHLPrice_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
        {
            var row = (InventoryItem)e.Row;
            if (row == null) return;

            try
            {
                InventoryItemExt invItemExt = PXCache<InventoryItem>.GetExtension<InventoryItemExt>(row);

                if (invItemExt.UsrAIWHLPriceChangeDate != null)
                {
                    invItemExt.Item.SetValueExt<InventoryItemExt.usrAIWHLPrevPriceChangeDate>(Base.Item.Current, invItemExt.UsrAIWHLPriceChangeDate);
                   // invItemExt.UsrAIWHLPrevPriceChangeDate = invItemExt.UsrAIWHLPriceChangeDate;
                }
                invItemExt.Item.SetValueExt<InventoryItemExt.usrAIWHLPriceChangeDate>(Base.Item.Current, PX.Common.PXTimeZoneInfo.Now);
               // invItemExt.UsrAIWHLPriceChangeDate = PX.Common.PXTimeZoneInfo.Now;
            }
            catch (Exception error)
            {
                PXTrace.WriteInformation("error: " + error);
            }
        }

Badge +11

@jinin - I think you meant

cache.SetValueExt<InventoryItemExt.usrAIWHLPrevPriceChangeDate>(Base.Item.Current, invItemExt.UsrAIWHLPriceChangeDate);

and 

cache.SetValueExt<InventoryItemExt.usrAIWHLPriceChangeDate>(Base.Item.Current, PX.Common.PXTimeZoneInfo.Now);

 

Userlevel 7
Badge +11

Yes @darylbowman .

Given the alternative approach to determine if it will work or not.

Userlevel 5
Badge +1

@jinin Unfortunately I get the following error with that method when verifying:

[2024-03-11 15:55:01.974] \App_RuntimeCode\InventoryItemMaint.cs(380): error CS1061: 'InventoryItemExt' does not contain a definition for 'Item'

@darylbowman Thanks.  Changing to cache.SetValueExt works.

 

One question:

After posting I had tried a few things myself and come up with:

cache.SetValueExt<InventoryItemExt.usrAIWHLPrevPriceChangeDate>(row, invItemExt.UsrAIWHLPriceChangeDate);

and

cache.SetValueExt<InventoryItemExt.usrAIWHLPriceChangeDate>(row, PX.Common.PXTimeZoneInfo.Now);

which also seem to work OK.

Is using Base.Item.Current preferable to using row?

 

Thanks for all your help,

Phil

Userlevel 7
Badge +11

Hi @ppowell ,


Oh, sorry typo mistake 🙂

You can use the row as well. 

Badge +11

Is using Base.Item.Current preferable to using row?

I personally use row

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