It's all about the answers!

Ask a question

How does a validator work when the validation fails


Alejandro Gay (1158) | asked Nov 06 '14, 4:52 p.m.
I have a validator to check that a specific field value is between certain range.
I have the precondition Attribute Validation defined in the Operation Behavior.

When a value is out of the range I have a little red indicator on one corner of the field and if I hover with the mouse on it , it shows the error message defined in the validator.
Then if I save the work item in this situation, its saved as if nothing happened!!

I was expecting that if one field was invalid the work item wouldn't be able to be saved and show a big error message on the top of the screen like when any other error happens.
 
so am I doing something wrong, or is how the validators works (almost useless)
how can I avoid a work item to be saved if a specific field is invalid?

4 answers



permanent link
Ralph Schoon (61.2k33643) | answered Nov 07 '14, 2:24 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
To block the save, you need to configure a precondition to prevent saving in case of a validation error.
See https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Validators

When the work item containing the attribute is saved. This is only true if the behavior of the save operation has been manually configured in Team Configuration, Operation Behavior to require attribute validation. Otherwise attributes are not checked when saved. Furthermore attributes which are not required and are left empty will never be validated


Comments
sam detweiler commented Nov 07 '14, 7:13 a.m.

he said he had the pre-condition configured

>I have the precondition Attribute Validation defined in the Operation Behavior.

I tested on my systems and with the pre-condition enabled,  the save was prevented.


Alejandro Gay commented Nov 07 '14, 8:29 a.m.

yes I have the precondition already there but still saves the work item and there is no additional configuration for this precondition



Alejandro Gay commented Nov 07 '14, 8:30 a.m. | edited unknown

yes I have the precondition already there but still saves the work item and there is no additional configuration for this precondition



Ralph Schoon commented Nov 07 '14, 8:51 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

The save is only prevented for "error" level. It has always worked for me so far. No idea why it should not.


permanent link
Alejandro Gay (1158) | answered Nov 07 '14, 8:30 a.m.
yes I have the precondition already there but still saves the work item and there is no additional configuration for this precondition



permanent link
Alejandro Gay (1158) | answered Nov 07 '14, 8:50 a.m.
and tried as well to make the attribute (timespent2) required just in case, but still not validated, actually in this case the validator is just a straight forced failed validation as the following code and you can see in the attached image that the validation works, but doesn't stop the saving

dojo.provide("com.example.HrsGtrThanZero");
dojo.require("com.ibm.team.workitem.api.common.Severity");
dojo.require("com.ibm.team.workitem.api.common.Status");
(function() {
var Severity = com.ibm.team.workitem.api.common.Severity;
var Status = com.ibm.team.workitem.api.common.Status;
dojo.declare("com.example.HrsGtrThanZero", null, {
validate: function(attributeId, workItem, configuration)
{ return new Status(Severity["ERROR"], "Validation failed");

} }); })();


Comments
Ralph Schoon commented Nov 07 '14, 9:04 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

We described this in https://jazz.net/library/article/1093 Lab 4 and 5. It has always worked for me. You can try to restart the server, close and open the work item. I don't have an idea why it wouldn't work. I'd suggest to open a PMR with support.


permanent link
Karen Steele (1.2k1131119) | answered Nov 10 '14, 11:00 a.m.
I work closely with Alex and have done some validation here - this project area was originally built in 3.0.1.3 - the server was then migrated to its current release of 4.0.5

I have tested out the attribute validator on a net new project area that was created after the server was upgraded to 4.0.5 and the validator works as expected and prevents saving.  I have confirmed the same in 5.0.1 so this appears to be inheritant of the migration of this project area from 3.0x to 4.0.5 and has rendered it "broken"

Comments
sam detweiler commented Nov 10 '14, 11:17 a.m.

If you delete the validator and then add it back, does this make a difference?

(Save the code first of course)


Karen Steele commented Nov 10 '14, 11:21 a.m.

nope added in just a basic decimal or regular expression and it still fails in this project area


Ralph Schoon commented Nov 10 '14, 11:59 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I have heard from other instances where project areas upgraded from early versions had issues with scripting. I would suggest to reach out to support and open a PMR.

They can have a look into your project area template and maybe find a reason for why it is not behaving as expected.

Your answer


Register or to post your answer.