Controlling field values

Fields values in dynamic dialogs can be manipulated dynamically.

Unbuffered mode is the default

Dynamic dialogs do not use program variables and thus behave by default as static dialogs using the UNBUFFERED mode: When an action is fired, and the corresponding trigger handler is executed, the field is validated and the value is available with the ui.Dialog.getFieldValue() method. Changing the value by program with ui.Dialog.setFieldValue() is automatically displayed to the corresponding form-field and visible when the control goes back to the end user.

For more details about the UNBUFFERED attribute, see The buffered and unbuffered modes.

Default form-field values

A dynamic input dialog created with ui.Dialog.createInputByName() behaves like a static INPUT dialog using the WITHOUT DEFAULTS option: The DEFAULT attribute of the form-field is not used.

A dynamic input array dialog created with ui.Dialog.createInputArrayFrom() behaves like a static INPUT ARRAY using the WITHOUT DEFAULTS option: The values set in the internal rows before starting the dialog will be used. However, like with a static INPUT ARRAY, when adding a new row, the DEFAULT attributes of the form-fields are used.

For more details about the WITHOUT DEFAULTS clause, see Form field initialization.

Setting and getting field values

A dynamic dialog stores field values in internal buffers based on the field definitions provided in the creation method. Access to these values is required, to implement the dynamic dialog.

For example, to set default values before entering the dialog loop, modifying and/or querying values during the dialog loop, and to get the entered values after dialog termination when accepted by the user.

To set or get values of fields controlled by a dynamic dialog, use respectively the ui.Dialog.setFieldValue() and ui.Dialog.getFieldValue() methods. These methods take a form field name as parameter, that can be provided in different notations. See Identifying fields in ui.Dialog methods for more details.

When implementing a display array or input array dynamic dialog handling a record list, the set/get field value methods apply to the current row. If you want to set or get field values of a particular row, first move to the row with the ui.Dialog.setCurrentRow() method.

This example copies the values from the fields in the current row of a display array dynamic dialog (d_list), to the field buffers of a record input dynamic dialog (d_rec):
CALL d_list.setCurrentRow("sr_custlist", index)
FOR i=1 TO fields.getLength()
    CALL d_rec.setFieldValue( fields[i].name,
               d_list.getFieldValue(fields[i].name)
         )
END FOR

Getting query conditions for a field

A dynamic dialog created with ui.Dialog.createConstructByName() handles query by example input (like CONSTRUCT).

To generate the SQL condition from the search value entered in a construct field, use the ui.Dialog.getQueryFromField() method, by passing the field name as parameter:
LET field_condition = DIALOG.getQueryFromField("customer.cust_name")
To build the complete WHERE part for the SELECT statement, iterate through all form fields and concatenate the form field condition by separating with the AND or with the OR operator:
FOR i=1 TO fields.getLength()
    LET field_condition = d.getQueryFromField(fields[i].name)
    IF field_condition IS NOT NULL THEN
       IF where_clause IS NOT NULL THEN
          LET where_clause = where_clause, " AND "
       END IF
       LET where_clause = where_clause, field_condition
    END IF
END FOR