Field Validation in IBM BPM Coach
Those who have worked on IBM BPM v8.0 know the difficulties with field validation in IBM BPM Coaches with the introduction of Coach Views. A traditional java script methods which we use for field validation in the lower version coaches (heritage coach as it is called now) won't work directly anymore. we need to implement hell lot stuff to perform validation on a field and display error message at the field if the data entered is not as per rules. Well, it just got easier in IBM BPM V8.0.1
In this post let us explore how to perform validation for given field in a coach. Below shown is a simple setup for performing validation on coach fields.
In IBM BPM v8.0.1, a new functionality called Fire Validation is introduced which is linked to a transaction (line joining the coach and next component in the flow) of a Boundary Event. In the above figure, you can see this in the properties of the transaction.
Fire validation has two options:
Validation service can be of any type of service except Human and AJAX services. In this example let us take server script component to write the field validation script and this in-turn is connected to "Stay on page Event"(which will move the control to the same page in-case validation is failed) . Figure 3 shows the script to validate two fields (as shown in figure 2) in this coach. The field Name is bound to "tw.local.Text" and the field Mobile is bound to "tw.local.mobileNumber".
A new system variable called CoachValidation has been introduced for the purpose of validation. This variable type is available in Coaches toolkit and a variable of this type is available as system variable which can be accessed as tw.system.caochValidation. Figure 3 Shows the Script for validating the fields Name and MobileNumber in the above coach. When the data entered in the given field is not as per the data rules, error needs to be set in tw.system.coachValidation variable by using the method tw.system.addCoachValidationError(). This will take three input parameter as shown in Figure 3.
First parameter is caochValidation variable itself, second parameter is the full name of the variable bound to the field in coach for which this validation applies to ("tw.local.Text" for the field "Name") , third parameter is the is error message that needs to be displayed in case data entered doesn't meet the validation. Figure 4 and Figure 5 shows the validation in UI.
On correcting the data and click on OK button, you know what happens !!! Happy learning.
Thanks for stopping by. If you like this post leave a comment, share it and do a g +1.
In this post let us explore how to perform validation for given field in a coach. Below shown is a simple setup for performing validation on coach fields.
![]() |
Figure 1 : Coach Validation Setup |
Fire validation has two options:
- Never - this means no validation is needed.
- Before - this means validation is required on invoking a Boundary Event. A green color circle with tick mark appears on the coach, which can be connected to a validation server script or validation service.
Validation service can be of any type of service except Human and AJAX services. In this example let us take server script component to write the field validation script and this in-turn is connected to "Stay on page Event"(which will move the control to the same page in-case validation is failed) . Figure 3 shows the script to validate two fields (as shown in figure 2) in this coach. The field Name is bound to "tw.local.Text" and the field Mobile is bound to "tw.local.mobileNumber".
![]() |
Figure 2: Fields in the Coach and Variables |
![]() |
Figure 3: Validation Script |
A new system variable called CoachValidation has been introduced for the purpose of validation. This variable type is available in Coaches toolkit and a variable of this type is available as system variable which can be accessed as tw.system.caochValidation. Figure 3 Shows the Script for validating the fields Name and MobileNumber in the above coach. When the data entered in the given field is not as per the data rules, error needs to be set in tw.system.coachValidation variable by using the method tw.system.addCoachValidationError(). This will take three input parameter as shown in Figure 3.
First parameter is caochValidation variable itself, second parameter is the full name of the variable bound to the field in coach for which this validation applies to ("tw.local.Text" for the field "Name") , third parameter is the is error message that needs to be displayed in case data entered doesn't meet the validation. Figure 4 and Figure 5 shows the validation in UI.
![]() |
Figure 4: Coach with improper data in fields |
![]() |
Figure 5: Coach with validation error for the fields with improper data. |
Thanks for stopping by. If you like this post leave a comment, share it and do a g +1.
Can you please let me know how to perform validation for select box ?
ReplyDeletecan we use two validation scripts on a single coach?
ReplyDeleteNo you cannot use two validation scripts for a single coach. You have keep your validations in a single server script for a given coach.
ReplyDeletebut if I have multiple buttons, depending upon the type of button can we issue two different types of validation scripts on a coach? I mean I want to validate certain fields on click of a button & some other fields for another button, provided all fields & buttons are on the same coach
ReplyDeleteHi Manali,
DeleteBelow link as solution for your problem.
http://www.ibpmcoding.com/2014/12/field-validation-in-ibm-bpm-coach.html
hi rajesh ,
ReplyDeleteyou can use the below code ..
bind name to selected item in configuration
if(tw.local.name== "")
{
tw.system.addCoachValidationError(tw.system.coachValidation, "tw.local.name", "Please Select an name field");
}
How can we use CoachValidation for a table?
ReplyDeleteIn client Side Human Service the below code will work....
ReplyDeleteIBM BPM v8.5.6
if(tw.local.name== ""){
tw.system.coachValidation.addValidationError ("tw.local.name", "Please Select an name field");
}
Coach validation is not working for passwords.
ReplyDeleteThere is no CoachValidationError message is shown in front of password field
Coach validation is not working on password field.
ReplyDeleteNo error message is shown