Solved

FieldSelecting Event with return value 'e.ReturnValue' does not save data to the SQL Database

  • 24 November 2023
  • 2 replies
  • 123 views

Userlevel 3
Badge

Dear Team,

I have created a Custom field (UsrContactPhone) on the Cases screen to display the Contact's phone number.

I used FieldSelecting Event to do this. The result displayed the value of Custom field (UsrContactPhone) on the Cases screen, but checking the ‘CRCase’ table on the SQL Database, the Custom field (UsrContactPhone) value is NULL.

I think the problem is the return value ‘e.ReturnValue’ is not okay but I don't have a solution yet.

I would like data of the Custom field to be saved to the SQL Database.


Please help me with the solution !

 

Best Regards,

NNT

 

==============

protected void CRCase_UsrContactPhone_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e, PXFieldSelecting InvokeBaseHandler)
    {
      if(InvokeBaseHandler != null)
      InvokeBaseHandler(cache, e);
      var row = (CRCase)e.Row;
            if (row == null)
            {
                return;
            }

            Contact contact = PXSelect<Contact,
                Where<Contact.contactID, Equal<Required<Contact.contactID>>>>.Select(Base, row.ContactID); 
            if (contact == null) { return; }
            e.ReturnValue = contact.Phone1 ;
            Base.Case.View.RequestRefresh();
      
    }

==============

 

icon

Best answer by vardan22 24 November 2023, 13:43

View original

2 replies

Userlevel 4
Badge +1

The ReturnValue property gets or sets the external presentation of the value of the DAC field.

The FieldSelecting event handler is used to:
• Convert 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).
• Convert the values of multiple DAC fields to a single external presentation.
• Provide additional information to set up a DAC field input control or cell presentation

In many cases, the FieldSelecting event handler is raised when a DAC field value is being prepared to be displayed on the UI. This event should be used to calculate database-unbound DAC field values.

For detailed information, you can read "FieldSelecting Event" in the “AcumaticaERP_FrameworkDevelopmentGuide.pdf” book.

Anyway if you want to save the UsrContactPhone field value into the db, that you can write FieldUpdated event handler for the ContactID field then in the event set the value for your custom field like this  cache.SetValueExt<DAC.usrContactPhone>(e.Row, “Value”)

Or you can write PXDefault attribute on the UsrContactPhone field then in the ContactID field updated event write cache.SetDefaultExt<DAC.usrContactPhone>(e.Row). 

Make sure CommitChanges property is set to true on the Customization Editor for the ContactID field.

Badge +11

As Vardan said, this event is commonly used to display the value of an unbound field. Is your field unbound?

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