Example 7

You have a request form that contains three numerical fields that represent percentages. For a user to save the request form, the sum of the values in the three fields must total 100%.

If the user clicks Save, and the sum is not 100%, you want to:

  • Display a pop-up alert that informs the user that he has specified invalid data

  • Set the background color of the three numerical fields to red

  • Abort the save operation

To make this work, you need an additional field to hold the sum, an "Apply on field change" rule to calculate the sum, and an "Apply before save" rule to correctly set the style of the three number fields.

To accomplish this, do the following:

  1. Add three numerical fields to your request type. For each field, specify Percentage Text Field as the validation to use and V_1, V_2, and V_3 as the tokens.

  2. To hold the sum, add a numerical field labeled Sum, and specify Percentage Text Field as the validation to use and SUM as the token.

    Note: Because this field is used only to keep track of the sum, you can hide the field.

  3. For each numerical field you created in step 1, define an advanced "Apply on field change" rule with three dependencies on when the field contains any value.

    Specify the Sum field in the Results table.

  4. Specify SQL-defaulting logic to calculate the sum of the three number fields, as follows:

    select nvl('[REQD.P.V_1]',0) + nvl('[REQD.P.V_2]',0) +
    nvl('[REQD.P.V_1]',0) + nvl('[REQD.P.V_2]',0) + nvl('[REQD.P.V_3]',0)
    from dual
  5. Create an advanced "Apply before save" rule with a dependency on when the Sum field is greater than 100.

    UI Rule logic: showMessage('The sum of values 1, 2, & 3 cannot be greater than 100. Currently they sum to [REQD.VP.SUM]. Please fix before taking WF action.', false); setFieldStyle("redBackground")

  6. Specify the three numerical fields in the Results table so that the background color style is applied to each of them.