Wednesday, April 1, 2015

IBM BPM Coach Validation with Multiple Buttons

In this post, I would like discuss about an issue with Coach Validation when there are multiple button validations available in a single Coach and possible solution for the same.

First let me describe the issue.
I have a coach which has three buttons, Button1, Button2, Button3. On click of each button, field validation should happen for the fields corresponding to each button. you can go through my other post related to UI Validation to understand on how to do validation in IBM BPM.
In the below image, 'tick' mark for each transaction (line) indicates that validation should be performed on click of that particular button. Unfortunately, even though validations has to be performed for multiple buttons, all the validations should be handled in a single Validation Script (you can notice in the Figure 1 that there is only one validation Script). In order to validate the fields corresponding a button, we need to identify which button is clicked up on. To identify the button clicked up on, we can bind a Boolean variable to each button  as shown in Figure 2 and on click of the button, the bound variable will be set to true.  In the validation Script, we can verify this button variable (Boolean) and if true, then validate the corresponding fields for a particular button.
Figure 1

Figure 2

Below image (Figure 3) shows the UI that we are going to consider for validation.

Figure 3

The catch here is, during validation, the service variables value can not be modified (not sure if IBM wantedly left it this way or if it is a bug in IBM BPM). Hence the Boolean variable bound to the button which is set to true when the button was clicked can not be reset to false while the control returns to the Coach .
When the Button1 is clicked up on, the fields 'Name' and 'Place' are validated  and error message is being displayed at the fields as shown in the figure 4 below.

Figure 4

Now when Button2 is clicked up on,  the expected behavior is  that, the fields 'Address Line1', 'AddressLine2' in Section 2 should  alone be validated and the error messages that are being displayed in Section1 should be disappear as we have now clicked Button2. But in actual, validations are happening for the fields in both Section1 and Section2 i.e., the fields corresponding to both Button1 and Button2 respectively. The reason is  that the Boolean variables which we have bound to the both the buttons are set to true, where as only the variable bound to Button 2 should be true and variable for Button 1 should be reset to false once the control goes back to coach as a result of failure in fields validation, which clearly is not happening (Even though I have tried to manually reset the Boolean variable by add a script in Pre script of Coach). Figure 5 below shows the validation on click of Button2 (You can see the fields in both the sections are being validated).

Figure 5

Solution for this issue:

As a solution for this issue, I have created a duplicate of Button Coach view (from Coaches toolkits) in the Process App and customized the Coach view to add the below code in-order to reset the variable which is bound to button, back to false once the control come back to Coach after the validation.
Go to Behaviour tab in the coach view and in View Event Handler search for the line, "context.trigger(function( )" and add the code highlighted below in the context.trigger callback function to reset the binding to false. The beauty is that, this piece of code will be executed only after the control comes back to Coach after the validation fails and resets the bound Boolean variable to false.

                    context.trigger(function() {
   _button.disabled = false; 
   domClass.remove(_button, "BPMButton-disabled");
   if (context.binding) {
    context.binding.set("value", false);

Now add this customized Button coach view in your coach instead of Button from "Coaches" Toolkit and you can find the coach validation for multiple Button is working as expected.
Hope this help full !!!

Thanks for stopping by. If you like this post leave a comment, share it and do a g +1.

1 comment:

  1. This was very useful and resolved the validation issue for multiple buttons on the same screen.