Creating Rule to Round Amount to Nearest Integer

Similar to Task B, you can define a rule on event Exit (exit) of the controls Claim Amount (ClaimAmount) and Third Party Amount (ThirdPAmount) that invokes a shared action round_value, which rounds to the nearest integer the amount specified as part of the control.

Procedure

  1. Select the Claim Amount control in the Customer Information pane on the Capture Claim form.
  2. Click the Rules tab.
  3. Click the Add Rule button against the event type Exit (exit).
  4. In the New Rule wizard, add the following inputs on the Rule Details dialog, and click Next:
    • Name:
      round_amount
    • Label:
      Round amount to nearest dollar.
  5. Leave the Exit (exit) event type unchanged in the Rule: Pick Events dialog and click Next.
  6. In the Add Action to Rule dialog, click the (plus) button to add an action.

    The Add Action to Rule dialog of the Add Action wizard opens.

  7. Select the radio button Create a new action and then the radio button Script Action, and click Next.
  8. In the Enter the action details page, type following values in the input fields.
    • Name:
      round_value
    • Label:
      Round the current value.
  9. Type the following script, and click Finish.
    var control = context.control;
    var value = control.getValue();
    var floatVal = parseFloat(value);
    var roundValue = Math.round(floatVal);
    if (floatVal != roundValue) {
        context.form.logger.info('float value' + floatVal + ' and round value' + roundValue + ' are different');
        control.setValue(roundValue);
    } 
    else {
        context.form.logger.info('float value' + floatVal + ' and round value' + roundValue + ' are equal');
    }
  10. In the Define Actions page, select the Shared check box, which will make the action shared, and click Finish.

    You should see this action appear under 'Shared Actions' in the Outline view.

  11. Edit the newly created rule and add an additional event by selecting the rule Round amount to nearest dollar in the Outline view, and then selecting the Events tab.
  12. Click the (plus) button and in the Select Event page select the event type Third Party Amount (ThirdPAmount), Update and click OK.

    This starts the rule on both controls: Claim Amount and Third Party Amount.

    Round_amount Event Defined


    Note: You can test this rule by adding a value with decimals in the amount field, and when you move to next field the amount will be rounded automatically.