Skip to main content
Answer

Why FieldSelecting event is not triggered?

  • October 1, 2023
  • 7 replies
  • 291 views

aaghaei
Captain II
Forum|alt.badge.img+10

Hello All,

I am trying to trigger FieldSelecting Event in a graph extension for EPApprovalProcess (ScreenID EP503010) but I am not sure why the event is not triggered while in the same extension RowSelected Event is triggered just fine. I had this issue in the past on a different graph that Generic Method was not working and with @Yuriy Zaletskyy guidance I switched to the traditional method DACName_FieldName_Event syntax style and worked fine (see below post). So I thought I had learnt from it so I tried both methods but it didn’t work. 

Please see the below code I have tried all possible methods but none of them are triggered.

using PX.Data;
using PX.Objects.EP;
using static PX.Objects.EP.EPApprovalProcess;

namespace MYTest
{
// ScreenID EP503010
public class MYEPApprovalProcessExt : PXGraphExtension<EPApprovalProcess>
{
public static bool IsActive() => true;

// This Row Selected Event IS triggered
protected virtual void _(Events.RowSelected<EPOwned> e, PXRowSelected baseHandler)
{
if (e.Row == null) return;
}

// The below Field Selecting Events are NOT triggered
protected virtual void _(Events.FieldSelecting<EPOwned, EPOwned.noteID> e)
{
if (e.Row == null) return;
}

protected virtual void _(Events.FieldSelecting<EPOwned, EPOwned.noteID> e, PXFieldSelecting baseHandler)
{
if (e.Row == null) return;
}

protected void EPOwned_NoteID_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
{
if (e.Row == null) return;
}

protected void EPOwned_NoteID_FieldSelecting(PXCache cache, PXFieldVerifyingEventArgs e, PXFieldSelecting baseHandler)
{
if (e.Row == null) return;
}
}
}

 

Best answer by Yuriy Zaletskyy

According to explanation in file Event.cs ( you can find that in your Acumatica instance, in the folder  App_Data\CodeRepository) event FieldSelecting is executed in the following cases:

The FieldSelecting event triggers in several situations:

  1. When the external representation (how the value displays in the UI) of a data access class field (DAC) value is requested from the UI or through the Web Service API.
  2. When these PXCache methods initiate assigning the default value to a field:
    1. Insert()
    2. Insert(object)
    3. Insert(IDictionary)
  3. While a field updates in the PXCache object due to any of these methods:
    1. Update(object)
    2. Update(IDictionary, IDictionary)
  4. When a DAC field value is requested through any of these PXCache methods:
    1. GetValueInt(object, string)
    2. GetValueIntField(object)
    3. GetValueExt(object, string)
    4. GetValueExt<Field>(object)
    5. GetValuePending(object, string)
    6. ToDictionary(object)
    7. GetStateExt(object, string)
    8. GetStateExt<Field>(object)

If to look on the screen EP503010, then first of all, we don’t see noteid field dispalyed. As outcome none of scenarios 1 is executed.

Scenario 2 is not exectued as well, because screen EP503010 doesn’t insert value into noteid field.

Scenario 3 is not executed, because screen EP503010 is read only, and updates are not executed.

Scenario 4 is not executed as well ( including all eight sub-scenarios).

 

But when I’ve added noteid field to the form, then event FieldSelecting gots executed. So to put simply, FieldSelecting wasn’t executed, and that is not a bug, but a feature.

Below goes a screenshot, from which I’ve generated scenarios.

 

7 replies

Zoltan Febert
Jr Varsity I
Forum|alt.badge.img+3
  • Jr Varsity I
  • October 2, 2023

Hi @aaghaei,

It looks like FieldSelecting doesn’t work for NoteID, but works for the other fields, for example  for RefNoteID.


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • October 2, 2023

@aaghaei  Is NOTEID filed added to the screen?

I think FieldSelecting event will fire only when that field is available on the screen.


Zoltan Febert
Jr Varsity I
Forum|alt.badge.img+3
  • Jr Varsity I
  • October 2, 2023

@Naveen Boga There is a Note column in the grid, it comes from a Projection. I believe NoteID is in Note, RefNoteID is in EPOwned table.


aaghaei
Captain II
Forum|alt.badge.img+10
  • Author
  • Captain II
  • October 2, 2023

@Naveen Boga and @Zoltan Febert thank you for the replies. NoteID is EPOwned it’s own note and RefNoteID is the parent document note. I do not believe NoteID is added to screen. I will try by NoteID added and post the result.


Yuriy Zaletskyy
Jr Varsity I
Forum|alt.badge.img+3

According to explanation in file Event.cs ( you can find that in your Acumatica instance, in the folder  App_Data\CodeRepository) event FieldSelecting is executed in the following cases:

The FieldSelecting event triggers in several situations:

  1. When the external representation (how the value displays in the UI) of a data access class field (DAC) value is requested from the UI or through the Web Service API.
  2. When these PXCache methods initiate assigning the default value to a field:
    1. Insert()
    2. Insert(object)
    3. Insert(IDictionary)
  3. While a field updates in the PXCache object due to any of these methods:
    1. Update(object)
    2. Update(IDictionary, IDictionary)
  4. When a DAC field value is requested through any of these PXCache methods:
    1. GetValueInt(object, string)
    2. GetValueIntField(object)
    3. GetValueExt(object, string)
    4. GetValueExt<Field>(object)
    5. GetValuePending(object, string)
    6. ToDictionary(object)
    7. GetStateExt(object, string)
    8. GetStateExt<Field>(object)

If to look on the screen EP503010, then first of all, we don’t see noteid field dispalyed. As outcome none of scenarios 1 is executed.

Scenario 2 is not exectued as well, because screen EP503010 doesn’t insert value into noteid field.

Scenario 3 is not executed, because screen EP503010 is read only, and updates are not executed.

Scenario 4 is not executed as well ( including all eight sub-scenarios).

 

But when I’ve added noteid field to the form, then event FieldSelecting gots executed. So to put simply, FieldSelecting wasn’t executed, and that is not a bug, but a feature.

Below goes a screenshot, from which I’ve generated scenarios.

 


Yuriy Zaletskyy
Jr Varsity I
Forum|alt.badge.img+3

@aaghaei does my comment ^ answers your question? Or you need some additional details?


aaghaei
Captain II
Forum|alt.badge.img+10
  • Author
  • Captain II
  • October 5, 2023

@Yuriy Zaletskyy thank you very much for the very thorough explanation and the follow up. Yes I tested it today and I got my answer and the issue is resolved. I think it is a very good reference for those who may come across the same issue. Thank you again.

 

thanks to @Naveen Boga who pointed out the same but I can only select one correct answer.