Solved

FieldUpdated Event clashing with base event(s)

  • 19 April 2023
  • 3 replies
  • 215 views

Userlevel 4
Badge +1

Hello, I’m struggling with the FieldUpdated event. 
On the Project Quotes form (PM304500) you enter Inventory IDs on the Estimation tab. When you commit an Inventory ID on a grid row, the description, uom and unit price are returned. Very similar to entering products onto a sales or purchase order. I would like to ignore the default price returned and update the field with my own value. 

The screen shot above shows that when SOFTLIC was entered the unit price was defaulted to 666.00

I’ve tried using the following (heavily cut back) code to update the unit price field but it’s not working, 22 doesn’t appear in the field:

        protected void CROpportunityProducts_InventoryID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var row = (CROpportunityProducts)e.Row;
string val = "22";
cache.SetValueExt<CROpportunityProducts.curyUnitPrice>(row, val);
}

I’m pretty certain that there is another event in the Acumatica code which is firing after my event. This makes sense since I can see that the description, uom and price fields are appearing. 

I wondered if there was a way to ensure my event fires last, or is there a way to find and extend the Acuamtica method which is populating the unit price? Or any other ideas on how I can achieve this requirement.

Thanks

icon

Best answer by Django 19 April 2023, 16:36

View original

3 replies

Userlevel 7
Badge +5

If you want to run your code after the base code set it up like this:

protected virtual void CROpportunityProducts_InventoryID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler)
{
InvokeBaseHandler?.Invoke(cache, e);

//your code goes here

}

See if that helps.

Userlevel 4
Badge +1
protected void CROpportunityProducts_InventoryID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler)
{
InvokeBaseHandler?.Invoke(cache, e);

var row = (CROpportunityProducts)e.Row;
string val = "22";
cache.SetValueExt<CROpportunityProducts.curyUnitPrice>(row, val);
}

Code is now shown above. 
It does look like the Base handler is called because when debugging, if I check the cache in the Watch Window I can see that the price is now populated, without InvokeBaseHandler?.Invoke(cache, e); the price wasn’t set.

I still set the price to 22 in my FieldUpdated handler and I can see that the price in the cache is updated, but this isn’t displayed on the screen. 

I wonder if another event is being called after this event perhaps? 

 

 

Userlevel 7
Badge +5

One other thing: By calling SetValueExt you’re asking Acumatica to set the value of 22 to curyUnitPrice and then to run any event code for that field.

If you change that to SetValue then you’ll just be pushing the value to the field without causing other events to fire.

That being said, I feel like for Unit Price that you do want other events to fire, however, so that your extended price calculates, among other fields.

Out of curiosity, can you add “virtual” to the declaration of the method between protected and void? I’m looking within the source code of PMQuoteMaint.cs and all of the event code has virtual.

 

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