Skip to main content
Solved

FieldSelecting doesn't seem to update the cache


Joe Schmucker
Captain II
Forum|alt.badge.img+2

I don’t use FieldSelecting (almost never) and I think I should have been using it a lot more.  However, When I set the Qty on a line in Bills and Adjustments, it just displays it on screen, and if you add a cost, it doesn’t extend the cost out.

You can see it defaults the Qty to 1.  But when you add an item, the extended cost is 0.

Here is my method:

        protected void APTran_Qty_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
        {
            var row = (APTran)e.Row;
            if (row == null) return;
            if (row.Qty == null || row.Qty == 0)
            {
                e.ReturnValue = 1m;
            }
        }

If I do this in the RowInserting it works, because I can actually update the cache.

        protected void APTran_RowInserting(PXCache cache, PXRowInsertingEventArgs e)
        {
            var row = (APTran)e.Row;
            if (row == null) return;
            if (row.Qty == null || row.Qty == 0)
            {
                cache.SetValueExt<APTran.qty>(row, 1m);
            }
        }

If FieldSelecting is not updating the cache, then what does it do?

Best answer by Naveen Boga

@Joe Schmucker I hope you have already received the correct details from @snikomarov36 regarding the field-selecting event, which displays the value in the UI but does not update the cache.

For your requirement, you should use either the Field Defaulting event (for the Qty field- Recommended) or the Row Inserting event to set QTY = 1 by default.

 

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

6 replies

snikomarov36
Acumatica Employee
Forum|alt.badge.img
  • Acumatica Employee
  • 54 replies
  • March 16, 2025

Hi ​@Joe Schmucker, the designed goal of field selecting event is to transform the internal DAC field’s value stored in server memory in the DAC field to an external representation that will be displayed in the UI or returned from Web API.

I strongly recommend the event documentation from Acumatica API Reference:
https://help.acumatica.com/(W(170))/Help?ScreenId=ShowWiki&pageid=e43e5162-c4b5-6bf8-8ff1-5c705ba73a05

According to the event’s documentation:

The FieldSelecting event handler is used to perform the following actions:

  • Conversion of the internal presentation of a DAC field (the data field value of a DAC instance) to the external presentation (the value displayed in the UI)
  • Conversion of the values of multiple DAC fields to a single external presentation
  • Provision of additional information to set up a DAC field input control or cell presentation

If I understand correctly, e.ReturnValue in the field selecting event handler is not set as the DAC field’s value in graph cache, it is returned to the UI as the external representation. There are other events to update DAC field’s value in cache - field defaulting, field updating, field updated, row inserting / inserted, row updating / updated.


Forum|alt.badge.img+6
  • Captain II
  • 556 replies
  • March 16, 2025

Hi Joe - what is it that you’re trying to do?

There is code in place that when you update the Qty, the line and extended line amounts will be updated.

I see a FieldUpdated routine for the Qty field. If the Qty <> zero the the curyUnitCost field FieldDefaulting routine is executed. curyUnitCost.FieldDefaulting has a bunch of logic. Updating that field will cause the declarative PXFormula on curyLineAmt to recalc the line total.

I’m wondering if you’ve overridden a method that is preventing the line from calculation the extended amount?


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3407 replies
  • Answer
  • March 17, 2025

@Joe Schmucker I hope you have already received the correct details from @snikomarov36 regarding the field-selecting event, which displays the value in the UI but does not update the cache.

For your requirement, you should use either the Field Defaulting event (for the Qty field- Recommended) or the Row Inserting event to set QTY = 1 by default.

 


Joe Schmucker
Captain II
Forum|alt.badge.img+2
  • Author
  • Captain II
  • 455 replies
  • March 17, 2025

@snikomarov36  Great link.  I saved it to my favorites!  Thanks for the writeup!

@Django I just want to default the qty to 1 on a new line.  That’s my only goal.  I did find that updating the field in RowInserting worked, but I didn’t know why using FieldSelecting didn’t work.

@Naveen Boga Thanks for confirming.  Based on the help from you all, I now know why FieldSelecting didn’t work, and that RowInserting is a good place to do my work.

Really appreciate you guys!


snikomarov36
Acumatica Employee
Forum|alt.badge.img
  • Acumatica Employee
  • 54 replies
  • March 17, 2025

@Joe Schmucker one other important thing is that with the field defaulting event handler the Qty field will be set to 1 only for the screen that uses the graph containing the field defaulting event handler.
If you always need to set Qty  to 1 by default for some DAC then you will need to add PXDefault attribute to the Qty DAC field. Here are great links that explain this:


Joe Schmucker
Captain II
Forum|alt.badge.img+2
  • Author
  • Captain II
  • 455 replies
  • March 17, 2025

Hi ​@snikomarov36   I will try it with the fielddefaulting.  I think in the past, I might have seen my default value get over written with whatever the default value is from the Acumatica DAC.  I’m going to try it anyway!  

FYI, I think the customer only wants it on this screen.  I’ll ask them.


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