Skip to main content
Answer

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

  • November 24, 2023
  • 2 replies
  • 328 views

nhatnghetinh
Captain II
Forum|alt.badge.img+11

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();
      
    }

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

 

Best answer by VardanV

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.

2 replies

VardanV
Jr Varsity III
Forum|alt.badge.img+1
  • Jr Varsity III
  • Answer
  • November 24, 2023

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.


darylbowman
Captain II
Forum|alt.badge.img+15

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