Skip to main content

I’m programmatically setting the value of a custom field depending on another field’s value. I want it to happen first thing when the page is displayed, before anything is changed by the user. I which event should I put the code?

Thanks is advance for any suggestions.

I believe the proper way would be to:

  • Create an event handler for FieldDefaulting of your custom field
  • Create an event handler for FieldSelecting of the dependency field

In the FieldSelecting event handler, call e.Cache.SetDefaultExt<> on the custom field to signal that FieldDefaulting should be called for the custom field.

In the FieldDefaulting event handler, check the value of the dependency field and set your custom field value.

 

My source is @Brian Stevens (Acumatica.dev)


Thanks so much for the reply, Daryl. It gives multiple errors, mostly, I’m sure, because I have no idea what I’m doing:

'PXFieldSelectingEventArgs' does not contain a definition for 'Cache' and no accessible extension method 'Cache' accepting a first argument of type 'PXFieldSelectingEventArgs' could be found

I don’t know enough about Acumatica to make it work. I was hoping there was something equivalent to the onPageLoad event in C# web development.

But I really appreciate your effort to help me.

David


Something like this:

protected virtual void _(Events.FieldDefaulting<DAC, DAC.customField> e)
{
DAC row = e.Row;
if (row is null) return;

// Get dependent field value and set custom field value
var value = ""; // dependent field

e.Cache.SetValueExt<DAC.customField>(row, value);
}

protected virtual void _(Events.FieldSelecting<DAC, DAC.dependingField> e)
{
DAC row = e.Row;
if (row is null) return;

// Call field defaulting event for 'CustomField'
if (row.DependingField is object)
e.Cache.SetDefaultExt<DAC.customField>(row);
}

 


Additionally, you may want to add some sort of check to make sure a value saved in the custom field is not overwritten when the record is selected again. I’m not certain that wouldn’t happen.


Reply