It's all about the answers!

Ask a question

Can i prevent to save a work item in a specific action depending on an attribute value?

Nicolás Rodríguez (3142125) | asked Jul 05 '12, 5:03 p.m.
I have a work item in a specific state, he can go to two different states using two different actions, it is possible validate if the work item can go to a specific state?, the validation would be with the values of the attributes in the work item.

i already have a java script that does the validation, and i already created a condition in  "Attribute  Customization", but i dont know how to use it, i thought that was in the Operation Behavior section, i created a preconditions for the save work item operation, but when i save the work item it doesnt show a error and let me save the work item with the wrong action.

this is my java Script:

dojo.require(""); // To access the work item attributes

(function() {

dojo.declare("com.example.validatorPhase", null, {

  matches: function(attributeId,workItem, configuration) {
var enumValue = workItem.getValue("requiereEspecificacion");
console.log("El valor del enum es "+enumValue);
var defectStatus = workItem.getValue(;   
        console.log("El valor del estado es " + defectStatus);
var  userAction=configuration.getWorkflowAction();
console.log("El valor de la accion es " + userAction);
        if(enumValue == "requiere_especificacion.literal.l4" && userAction=="flujoEvolutivo.action.a24" ){
return true;
}else if(enumValue == "requiere_especificacion.literal.l2" && userAction=="flujoEvolutivo.action.a24" ){
return false;
}else if(enumValue == "requiere_especificacion.literal.l4" && userAction=="flujoEvolutivo.action.a3" ){
return false;
}else if(enumValue == "requiere_especificacion.literal.l2" && userAction=="flujoEvolutivo.action.a3" ){
return true;
return true;

Accepted answer

permanent link
Ralph Schoon (63.2k33646) | answered Jul 09 '12, 2:47 a.m.
I am not aware that you can detect a state change in Java script. Maybe you can try to use a calculated attribute to store the last state and check if the current state is different and detect the state change that way. If that works for you and you find it acceptable, this might be a solution.

In a Java based precondition or followup action the state change can easily be detected and it is not all that hard to do either, especially since the examples mentioned above already show that code.
Nicolás Rodríguez selected this answer as the correct answer

4 other answers

permanent link
Nicolás Rodríguez (3142125) | answered Jul 06 '12, 3:29 p.m.
Hi Ralph
is there another way to accomplish this? to do a validation on state change of a work item? or this cant be done?

permanent link
Ralph Schoon (63.2k33646) | answered Jul 06 '12, 11:09 a.m.
edited Jul 06 '12, 11:09 a.m.
Hi Nicolas,

I am sorry, I missed that you wanted to trigger on a state change.

All you can do in java script today, I think, is to detect the current state and say the value is not valid in this state.

You could try to create a precondition that looks at the old state and the new state and based on this data checks if the data is valid. See as a starter.

permanent link
Nicolás Rodríguez (3142125) | answered Jul 06 '12, 11:02 a.m.
Hi Ralph

Thank you for your answer.

But there is a problem, i can´t obtain the workflow action in a validator and i need it to validate if it can be saved with a specific action, because configuration.getWorkflowAction(); always return null in a validator, that´s why i did it on a conditional, but the conditional only can be used in Operation Behavior and cant be assigned to a attribute of a work item.

permanent link
Ralph Schoon (63.2k33646) | answered Jul 06 '12, 2:47 a.m.
Hi Nicolas,

you can use scripts to prevent saving on a validation error.

It can be used in conjunction with the Attribute Validation precondition for saving a work item (server).
With this precondition set it prevents saving work items with attribute validation issues of level error. Validation results with level Warning or Information can still be saved.

You need to configure this Validation precondition with your validator.

Please have a look at for how to properly return the status. It looks like

        var severity= "ERROR";
        var message= "Date must not be earlier.....";
        // Compare the two dates and make sure endDate is not earlier than beginDate
        if (, beginDate) >= 0) {
            return Status.OK_STATUS;
        } else {
            return new Status(Severity[severity], message);

Your answer

Register or 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.