Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved


Chapter 1 Getting Started : Tutorial 4: Rules, Events, and Actions

Tutorial 4: Rules, Events, and Actions
This tutorial shows how to create rules that fire when a pre-defined event(s) occur and invoke actions associated with them.
The following tasks are explained:
 
Task A: Create a Rule to Compute Age (Capture Claim Form)
The rule you will create in this section will:
Listen for changes in the value of Birth Date (BirthDate) parameter.
Create a computation action that will compute age based on updates to the value of BirthDate parameter and Customer Age(CustAge) parameters. Since there is already a binding between Customer Age(CustAge) parameter and Age(CustAge) control, the Age control will be automatically updated with the computed value.
1.
Select the parameter Customer Age (CustAge) from the Data node of the Outline View on the Capture Claim form.
Figure 33 Add Binding for the Customer Age Parameter
2.
Click the Add Binding button .
The Create Binding dialog opens.
3.
Select the radio button Update this property using Computation Action and click Next.
4.
In the window Rule: Edit Computation Action, type following JavaScript code as part of an expression that computes the age based on the birth date specified:

 
var birthDate = context.newValue;
context.form.logger.info('compute_age: Birth date received='
    + birthDate);
if (birthDate != null) {
    var now = new Date();
    var age = now.getFullYear() - birthDate.getFullYear();
    //compute age
    if (now.getMonth() <= birthDate.getMonth() && now.getDate()
        <= birthDate.getDate()) {
        age = age--;
    }
    if (age <= 0) {
        age = 0;
    }
    context.form.logger.info('compute_age: Returning the age         value=' + age);
    //populate age field with age computed.
    age;
} else {
    0;
}

 
5.
Click Next.
The Rule: Pick Events page opens.
6.
Click (plus) button to select an event.
The Select Event dialog opens.
Figure 34 Select Event Dialog
7.
Select Update property of the parameter Birth Date (BirthDate).
8.
9.
Click Finish.
Test your script by clicking the GWT Preview tab, specifying a value for the birth date, and pressing the Enter key. The calculated age will appear in the Age field.
Task B: Create Rule to Update Required Option for Guardian When Age < 21
As part of this task, you will create a rule that updates the required option on the control Guardian Name based on Customer Age parameter value.
1.
Select parameter Customer Age (CustAge) from the Data node of Outline View on the Capture Claim form.
2.
Click the Rules tab on the Properties View.
Figure 35 Select the Event Type
3.
The Rule Details page opens.
Figure 36 Rule Details Page
 
4.
Type the following values for the input fields on Rule Details screen and click Next:
Name: set_guardian_required
Label: Guardian required when Age < 21.
5.
Leave the Update (update) event type in the Rule: Pick Events page unchanged and click Next.
The page Define Actions opens.
Figure 37 New Rule Dialog, Define Actions Page
6.
Click (plus) button .
The page Add Action to Rule opens.
7.
Select the radio button Create a new action and then Script Action.
8.
Click Next.
The Enter the action details page opens.
Figure 38 Enter the Action Details
9.
Name: set_guardian_required
Label: If customer age is less than 21, it will set the guardian field as required.
10.

 
context.form.logger.info('set_guardian_required: Customer age     received:' + context.newValue);
var age = context.newValue;
control.GuardianName.setRequired(age < 21);

 
11.
Click Finish and again Finish twice.
Task C: Create Rule to Round Amount to Nearest Dollar
This task is very similar to Task B: a rule is defined on event Exit (exit) of the controls Claim Amount (ClaimAmount) and Third Party Amount (ThirdPAmount) that will invoke a shared action round_value, which rounds to the nearest integer the amount specified as part of the control.
1.
Select the Claim Amount control in the Customer Information pane on the Capture Claim form.
2.
Click the Rules tab.
Figure 39 Claim Amount Control, Rules Tab
3.
Click the Add Rule button against the event type Exit (exit).
4.
In the New Rule wizard, Rule Details page, add the following inputs 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 page and click Next.
6.
In the Add Action to Rule page, click (plus) button to add an action.
The Add Action wizard, Add Action to Rule page opens.
7.
Select the radio buttons 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.

 
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.
Figure 40 Edit an Event
12.
Click (plus) button and in the Select Event page select the event type Third Party Amount (ThirdPAmount), Update and click OK.
This will start the rule on both controls: Claim Amount and Third Party Amount.
Figure 41 Round_amount Event Defined
 
Task D: Create Rules that Display Hint on Specifying Claim Amount Controls
This task creates a rule that displays a hint to a user when specifying the Claim Amount or Third Party Amount controls.
1.
Select Claim Amount control on the Capture Claim form.
2.
Click the Rules property tab.
3.
4.
In the New Rule wizard, Rule Details page, add following inputs on the Rule Details screen and click Next:
Name: show_rounding_hint
Label: Display hint on entering claim amount controls.
5.
In the Rule: Pick Events page, leave the Enter (enter) event type unchanged and click Next.
6.
Click (plus) button in the Define Actions page.
The Add Action to Rule page opens.
7.
Select options Create a new action and Script Action and click Next.
8.
Name: show_rounding_hint
Label: Display hint on entering.
9.

 
var hint = "The value will be rounded to nearest dollar";
context.control.setHint(hint);

 
10.
In the Define Actions page, select Shared check box against the action.
This will make the action shared.
11.
Click Finish.
12.
Edit the newly created rule and add an additional event by selecting the rule Display hint on entering claim amount controls in the Outline View, and then selecting the Events tab.
13.
Click (plus) button and in the Select Event page select the event type Third Party Amount (ThirdPAmount), Update and click OK.
This will make the rule to be invoked on specifying both the controls Claim Amount and Third Party Amount.
As a result, whenever you specify data for the controls Claim Amount and Third Party Amount, the hint will be displayed.
Note that the control Third Part Amount will be visible only if the third party was involved in the accident, which is not the case in this tutorial. In the step Set Third Party Information Pane we decided to make the Third Part Information pane invisible in case there is no third party involved in this accident.
Task E: Create Rules that Hide Hints on Exiting Amount Controls
This task creates a rule that hides the hint created in the previous rule as part of Task D when exiting the Claim Amount or Third Party Amount controls.
1.
Select Claim Amount control on the Capture Claim form.
2.
Click the Rules tab.
3.
4.
Add the following inputs on the Rule Details screen and click Next:
Name: hide_rounding_hint
Label: Hide hint on exiting claim amount controls.
5.
In the Rule: Pick Events page, leave the Exit (exit) event type unchanged in the Choose Events page and click Next.
6.
Click (plus) button in the Define Actions page.
The Add Action to Rule page opens.
7.
Select options Create a new action and Script Action and click Next.
8.
Name: hide_rounding_hint
Label: Hide hint on exiting.
9.
var hint = "";
context.control.setHint(hint);
10.
In the Define Actions page, select Shared check box against the action.
This will make the action shared.
11.
Click Finish.
12.
Edit the newly created rule and add an additional event by selecting the rule Hide hint on exiting claim amount controls in the Outline View, and then selecting the Events tab.
13.
Click (plus) button and in the Select Event page select the event type Third Party Amount (ThirdPAmount), Update and click OK.
This will start the rule when specifying the controls Claim Amount and Third Party Amount.
As a result, whenever you exit the controls Claim Amount and Third Party Amount, the hint will be hidden.
Task F: Create Rules to Display Context-Specific Hints on Specifying Customer Description Control
This task creates a rule that displays the hint to user when specifying the description for the field Description in the Accident Information pane.
1.
Select the Customer Description control in the Accident Information pane of the Capture Claim form.
2.
Click the Rules tab.
3.
4.
Add following inputs on the Rule Details page and click Next:
Name: show_personal_injury_hint
Label: Display conditional hint based on injury flag.
5.
In the Rule: Pick Events page, leave the Enter (enter) event type unchanged and click Next.
6.
Click (plus) button in the Define Actions page.
The Add Action to Rule page opens.
7.
Select options Create a new action and Computation Action and click Next.
8.
Name: show_conditional_hint
Label: Sets the hint based on PesonalInjury flag.
Destination: Select the Hint property of the control Accident Description(AccDescription) in the Choose Destination page and click OK.
Make sure that you have selected Show Controls and Panes as a filter in the upper right corner of the screen and click Finish.
Figure 42 Choose Hint Property of the AccDescription Control
 
9.

 
var personalInjury = control.PersInjury.getValue();
var hint = '';
if (personalInjury == 'YES') {
    hint = 'Please describe personal injury.';
}
hint;

 
10.
Click Finish twice.
As a result of this rule, when option yes is selected for Personal Injury a hint will be displayed when specifying the Description value.
Task G: Create Rules to Hide Hints on Exiting Customer Description Control
This task creates a rule that hides the hint that is created in the previous rule as part of Task F when exiting the Description control.
1.
Select Customer Description control on the form Capture Claim and click the Rules tab.
2.
3.
In the Create New Rule wizard, add following inputs in the Rule Details page and click Next:
Name: hide_conditional_hint
Label: Hide hint on exiting claim amount controls.
4.
Leave the Exit (exit) event type unchanged and click Next.
5.
Click (plus) button in the Define Actions page.
The Add Action to Rule page opens.
6.
Select options Create a new action and Computation Action and click Next.
7.
Name: hide_conditional_hint
Label: Hide the hint.
Destination: Select the Hint property of control Accident Description (AccDescription) and click OK.
Destination: Select the Hint property of the control Accident Description (AccDescription) in the Choose Destination page and click OK.
Make sure that you have selected Show Controls and Panes as a filter in the upper right corner of the screen and click Finish.
8.
9.
Click Finish twice.
Whenever you exit the Customer Description control, its hint will be hidden.
Task H: Defining Custom Actions for Buttons
In most cases, buttons on a form are configured with one of the pre-defined actions provided in TIBCO Forms. The left-most button on the Interview Witness form, for example, was created automatically when the form was generated. This button is configured with the standard rule Cancel that invokes the system action Cancel when the Cancel button is selected.
However, the Interview Witness form also contains three custom buttons to control the flow of the business process:
If the button labeled Failed - Try Again is clicked, the flow returns once again to the Interview Witness user task so that another attempt will be made to contact the witness.
The button labeled Failed - Do Not Try Again and
The button labeled Completed send the process to its end event.
In this step, you will write the action scripts that control the functionality of these custom buttons. Table 4 shows three custom buttons and the action associated with the event Select - when the control is clicked or otherwise selected.
This action sets the witness_stat variable to a value of TRY_AGAIN, and then invokes the standard submit action that is defined by the system.
This action sets the witness_stat variable to a value of FAIL, and then invokes the standard submit action that is defined by the system.
This action sets the witness_stat variable to a value of SUCCESS, and then invokes the standard submit action that is defined by the system.
The action defined for each of the three custom buttons invokes the standard Submit action that is defined by the system. Before doing so, each action defines the witness status by setting the value of the WitStatus control, which is used in the logic of the Contact Witness Again gateway to determine the flow of the business process. A value of TRY_AGAIN restarts the Interview Witness user task. A value of FAIL or SUCCESS moves the Claims Process business process to its end event.
Perform the following procedures to configure the custom buttons.
Configure the Failed - Try Again Button
1.
Open the Interview Witness form in the Form Designer.
2.
Click the Failed - Try Again button and view its Properties View.
3.
Click the Rules tab on the Properties View.
4.
5.
Add following inputs in the Rule Details page and click Next:
Name: failed_try_again
Label: Witness status = "TRY_AGAIN"
6.
Leave the Select (select) event type unchanged in the Rule: Pick Events page and click Next.
7.
Click (plus) button in the Define Actions page.
The Add Action to Rule page opens.
8.
Select options Create a new action and Script Action and click Next.
9.
Name: failed_try_again
Label: Witness status = "TRY_AGAIN"
10.
this.getForm().getControl("witstatus").setValue("TRY_AGAIN");
this.getForm().invokeAction("submit",this);
11.
Click Finish twice.
Configure the Failed - Do Not Try Again Button
1.
Open the Interview Witness form in the Form Designer if it is not already open.
2.
Click the Failed - Do Not Try Again button and view its Properties View.
3.
Click the Rules tab on the Properties View.
4.
5.
Add following inputs in the Rule Details page and click Next:
Name: failed_dont_try_again
Label: Submit with witness status = "FAILED"
6.
Leave the Select(select) event type unchanged in the Choose Events page and click Next.
7.
Click (plus) button in the Define Actions page.
The Add Action to Rule page opens.
8.
Select options Create a new action and Script Action and click Next.
9.
Name: failed_dont_try_again
Label: Submit with witness status = "FAILED"
10.
this.getForm().getControl("witstatus").setValue("FAILED");
this.getForm().invokeAction("submit",this);
11.
Click Finish twice.
Configure the Completed Button
1.
Open the Interview Witness form in the Form Designer.
2.
Click the Completed button and view its Properties View.
3.
Click the Rules tab on the Properties View.
4.
5.
Add following inputs on Rule Details page and click Next:
Name: success
Label: Submit with witness status = "SUCCESS"
6.
Leave the Select (select) event type unchanged in the Choose Events page and click Next.
7.
Click (plus) button in the Define Actions page.
The Add Action to Rule page opens.
8.
Select options Create a new action and Script Action and click Next.
9.
Name: success
Label: Submit with witness status = "SUCCESS"
10.
Type this script this.getForm().getControl("witstatus").setValue("SUCCESS");
this.getForm().invokeAction("submit",this);
11.
Click Finish twice.
Summary of Tutorial 4
In this tutorial, you wrote a number of action scripts that enhance the functionality of the Capture Claim and Interview Witness forms. You learned how to create rules to compute age, update options, round amounts, display hints, hide hints, and so on.
Finally, you learned how to create custom submit buttons that work in conjunction with gateways to control the flow of the business process.
 

Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved