A JavaScript function can be used to perform custom formatting and validation of bound fields. This is done by selecting the 'Custom' field formatting type and providing the name of the desired JavaScript function, as shown here:

The function will be called both when the screen is displayed (to format data provided by the RPG program), and when a change is made to a field and the screen submitted (to validate user input and to revert data to program formatting). The function will receive a single argument, which is an object containing properties that provide information about the field, along with the field data. The parameter object includes the following properties:

The function should look at the "revert" property to determine whether its being called to format data, or to validate user input and revert to server format. In either case, the function should return the desired value as a string. If the function is called with the "revert" flag present, then it can also cause a validation message to appear by returning an object with a property "msg". The value of the "msg" property should be a string which will display in a validation tool-tip beside the field. When the function returns an object with "msg" property, the submit will be cancelled, and the user will have to correct the input and attempt to submit the screen again. 

The following example code processes a 1-character server value "Y" or "N" and formats this as "Yes" or "No": 

function myFormatter(params) {

  if (params.revert) {

    if (params.value == "Yes") {
      return "Y";
    }
    else if (params.value == "No") {
      return "N";
    }
    else {
      return {"msg":"Invalid value. Enter \"Yes\" or \"No\"."};
    }

  }
  else {

    if (params.value == "Y") {
      return "Yes";
    }
    else {
      return "No";
    }

  }
}