Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

How does a validator work when the validation fails

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?

0 votes



4 answers

Permanent link
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

0 votes

Comments

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.

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


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


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


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


0 votes


Permanent link
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");

} }); })();

0 votes

Comments

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
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"

0 votes

Comments

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

(Save the code first of course)

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

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 log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details

Question asked: Nov 06 '14, 4:52 p.m.

Question was seen: 4,333 times

Last updated: Nov 10 '14, 11:59 a.m.

Related questions
Confirmation Cancel Confirm