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


Chapter 1 Getting Started : Tutorial 3: Validations

Tutorial 3: Validations
This tutorial shows how use scripts to create validation rules for controls. These scripts will validate the data specified by the user at runtime. In this tutorial, you will create validation scripts for individual controls on the Capture Claim form.
To complete this tutorial, follow these steps:
 
Task A: Switch to Solution Design Mode
To change mode from Business Analysis to Solution Design, click the “triangle and rule” toolbar button to open the dropdown list that lets you select the desired mode.
Figure 29 Change to Solution Design Mode.
Task B: Add Validation for Phone Field
This validation script checks the phone number specified by the user to make sure it is in a format that can be properly handled by our business process application.
1.
2.
Click the Validations tab on the control’s Properties View.
3.
Click the Add New Validation button.
The Define Validation page of the Define Validation dialog opens.
Figure 30 Define Validation Page
4.
In the Name field type the following:
phone_number_syntax
5.
Select On Value Change radio button.
6.

 
//Retrieve the phone value
var phone = this.getValue();
if(phone != null && phone != ""){
//verify it is in the format 888-888-8888
var strippedPhone = '';
var strippedPhone = '';
for(var i=0; i<phone.length; i++){
var c = phone.charAt(i);
var isNonDigitChar = isNaN(parseInt(c));
if(!isNonDigitChar){ // check if c is a digit
strippedPhone += c;
}
}
strippedPhone.length == 10;
} else{
true;
}

 
7.
Select the Message type as Custom and type the following text in the Message area:
Phone number must be of the form: (888) 888-8888.
Figure 31 Completed Validation Definition for the Phone Field
 
An error message will be displayed if text is specified in an invalid format.
When you select On Value Change, the error message is displayed when the user specifies an invalid value and then clicks in another field, that is, at the moment the Phone field loses focus. The other option is to set the validation script to run when the form is submitted, or when the user has completed the form and clicked the Submit button. Consider which of the two options is more convenient for your user, depending on the nature of the validation. Generally, validations of the syntax of specified values are best performed when the field value is updated.
When more than one control is involved, such as when you want to ensure that at least one of two or more fields are filled in, you can choose On Form Submit. You will see this below, in the validation for the Email field, when you create a validation script to ensure that the user provides either the customer’s phone number or email address, but not necessarily both.
8.
Click Finish.
Task C: Add Syntax Validation for Email Field
1.
Click the Email field.
2.
Click the Validations tab on the control’s Properties View.
3.
Click the Add New Validation button.
The Define Validation dialog opens.
4.
In the Name field type the following:
email_syntax
5.
Click the radio button On Form Submit.
6.

 
var email = this.getValue();
if(email != null && email != ""){
//Match format xxx@xxx.xxx
var match = RegExp("(.)+@(.)+\\.(.)+").test(email);
match;
} else{
true;
}

 
7.
Email must be of the form xxx@xxx.xxx.
8.
Click Finish.
Task D: Add a Second Validation for Email Field
This validation will ensure that a value is specified for either the Email or Phone field. The user is not required to provide values for both in this application.
1.
Click the Email field.
2.
Click the Validations tab on the control’s Properties View.
3.
Click the Add New Validation button.
The Define Validation dialog opens.
4.
email_or_phone_required
5.
Click the radio button On Value Change.
6.

 
//Check one of email and phone fields are entered
if((f.CustPhone == null || f.CustPhone == "") &&
(f.CustEmail == null || f.CustEmail == "")){
false;
} else{
true;
}

 
7.
Either customer phone number or email address must be entered.
8.
Click Finish.
Task E: Add Validation for Date of Birth Field
1.
Click the Date of Birth field.
2.
Click the Validations tab on the control’s Properties View.
3.
Click the Add New Validation button.
The Define Validation dialog opens.
4.
In the Name field type the following:
birth_date_validation
5.
Click the radio button On Value Change.
6.

 
var date = this.getValue();
var now = new Date();
//Validate birth date some time before today's date and
//within 120 years
if(date == null ||
(date < now && now.getFullYear() - date.getFullYear() < 120)){
true;
} else{
false;
}

 
7.
Enter a valid birth date which is a past date and in the range of last 120 years.
8.
Click Finish.
Task F: Examine Auto-Generated Validation for Age Field
In this task you will examine an auto-generated validation script and edit its error message. Form fields, like the Age field, that are auto-generated from user task parameters that are themselves based on Integer Number data fields include a validation script that checks that the runtime input is a number. The auto-generated script also checks that the value is not longer than 3 digits. The allowed length is based on the length property of the data field from which the control is generated.
To see the Properties View for the CustAge data field:
1.
Figure 32 Find Date Field CustAge
2.
Notice the properties of the data field, including the Length property (3 digits). The Properties View also shows that the data field is used by the Capture Claim user task.
The customer age property was set when data fields were added as parameters to the user task, a step that was performed for you when the business process was created. The script is set by default to be executed when the form is submitted.
Task G: Edit Validation for Claim Amount Field
In this task you will examine another auto-generated validation script, change the setting for when input data are validated, and edit the error message.
1.
Click the Claim Amount field in the Customer Information pane.
2.
Click the Validations tab on the control’s Properties View.
3.
Validation is now performed as soon as the user specifies a value for this field.
4.
this.getForm().numberFormat(this.getValue(),17,2);
5.
Verify that the text in the Message area is as follows:
Claim Amount not valid. Expecting numeric format 15.2.
Task H: Add Validation for Time of Accident Field
1.
Click the Time of Accident field.
2.
Click the Validations tab on the control’s Properties View.
3.
Click the Add New Validation button.
The Define Validation dialog opens.
4.
In the Name field type the following:
accident_time_validation
5.
Click the radio button On Value Change.
6.

 
//Accident time must not be in the future
var accTime = this.getValue();
var now = new Date();
if(now < accTime){
false;
} else{
true;
}

 
7.
Edit the text in the Message area to the following:
Accident time must not be in the future.
8.
Click Finish.
Task I: Add Validation for Phone Field
1.
2.
Click the Validations tab on the control’s Properties View.
3.
Click the Add New Validation button.
The Define Validation dialog opens.
4.
In the Name field type the following: phone_number_syntax
5.
Select the On Value Change. radio button.
6.

 
//Retrieve the phone value
var phone = this.getValue();
if(phone != null && phone != ""){
//verify it is in the format 888-888-8888
var strippedPhone = '';
var strippedPhone = '';
for(var i=0; i<phone.length; i++){
var c = phone.charAt(i);
var isNonDigitChar = isNaN(parseInt(c));
if(!isNonDigitChar){ // check if c is a digit
strippedPhone += c;
}
}
strippedPhone.length == 10;
} else{
true;
}

 
7.
Phone number must be of the form (888) 888-8888.
8.
Click Finish.
Summary of Tutorial 3
This tutorial showed how to create validations for fields on a form to ensure that valid data are specified by the user at runtime.

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