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
Select the
Claim Amount control in the Customer Information pane on the
Capture Claim form.
Click the
Rules tab.
Click the
Add Rule button against the event type
Exit (exit).
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.
Leave the
Exit (exit) event type unchanged in the
Rule: Pick Events dialog and click
Next.
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.
Select the radio button
Create a new action and then the radio button
Script Action, and click
Next.
In the
Enter the action details page, type following values in the input fields.
Name:
round_value
Label:
Round the current value.
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');
}
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.
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.
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.