Form events - inconsistent reference to select fields

I ran into what looks like a bug while writing events on a form. This is a multi-step form under SC 9.7, using the new multi-step form function.

TLDR: When trying to set a select field to a specific value in PHP code, I have to refer to the field’s label from the onRefresh event, but I have to refer to field’s value when using an AJAX event. In my case the field I am trying to set has a manual lookup and a title. I haven’t tested to see if that matters.

Shouldn’t references to the drop-down always be either the label or the value? Not one or the other depending on context?

Long explanation:

My form has a select field, “employee”, where the box is checked for “EVENTS onChange” - “Use AJAX to reload other fields of type Select, Double Select, Radio and Checkbox.”.

So “employee” has that box checked and then on the list of other fields, “serial” is selected (there is an asterisk next to “serial” indicating it will be reloaded when “employee” changes). There are also other fields selected, but I’m leaving them out to simplify this.

The {employee} field has a value of an employee’s ID number and a label of the employee’s name.

The {serial} field is a drop-down (select) with an automatic lookup. That lookup is set up as a union query that has 3 parts.

Select serial_number, concat(serial_number, '-', model) from inventory where employee_id = {employee}
select 'N/A', 'N/A'
union select serial_number, concat(serial_number, '-', model) from inventory where employee_id <> {employee}

This has the effect of creating a drop-down where the first displayed item will be the employee’s assigned serial number and model, the second displayed item will be ‘N/A’, and the remaining displayed items will be all of the serial numbers and models of the remaining items in the inventory.

The field does not use a title, so if the employee has no assigned serial number in the inventory, then the first part of the union query is null and ‘N/A’ will be the first item on the list and will be selected by default.

So when {employee} is changed, the ajax event fires to set {serial}. So far, so good.

There is a third field which is the result of an inspection of the item with the serial number shown in {serial}. That field, “result”, is a select with a manual lookup. Its labels and values are Pass (Pass), Fail (Fail), and N/A (N/A). It also has “Use Title” set to Yes, with a title label of “–Select–” and a title internal value of nothing.

So {result} is a list of values/labels as follows:

Value / Label
(nothing) / --Select--
N/A / N/A
Pass / Pass
Fail / Fail

What I want the form to do is:

  • User selects an employee in {employee}
  • If there was a record found for that employee in the inventory, then {serial} will display their serial number and {result} should show “–Select–”. “Result” is a required field and since the title has no internal value, the form will force the user to make a selection for “result”.
  • If there was no matching record found in the inventory, {serial} will have “N/A” at the top of the list. I want {result} to automatically also be set to “N/A”.

I found that when the user makes a selection in employee, that the “onRefresh” event of the form fires once for every field that is selected in the “Use AJAX to reload other fields of type Select, Double Select, Radio and Checkbox.”.

So I use the onRefresh event to set the result field as follows:

if ( !empty ({serial}) )
	if ( {serial} == 'N/A' )
		{result} = 'N/A';
		{result} = '--Select--';

This works as expected.

I also have an AJAX event that will update the result field when the user changes the serial field directly. If they change it from N/A to any other value, I want to force the result field back to the title, which is “–Select–”.

This is done in the “Ajax Events” part of the form. I created a new Ajax event for “serial”, onChange. In that event I have the following code:

if ( {serial} !== 'N/A' && {result} == 'N/A' )
	{result} = '';

This is where I ran into the inconsistency in the reference to the select field. Note that in the onRefresh event I change {result} by using

{result} = '--Select--';

…which is the label of that item in the list.

But it wasn’t working when I used the exact same line of code in the Ajax event. I found that to make it work in the Ajax event, I had to use

{result} = '';

…which is the value of that item in the list.

So in onRefresh the label reference works, and in Ajax the value reference works. This took me quite a while to figure out as in other cases where I wanted to set a different result field to “N/A” when the user manually selected N/A for another item, the same code worked in both places since “N/A” was both the label and the value.