Can i prevent to save a work item in a specific action depending on an attribute value?
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.provide("com.example.validatorPhase");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes"); // To access the work item attributes
dojo.require("com.ibm.team.workitem.api.common.Severity");
dojo.require("com.ibm.team.workitem.api.common.Status");
(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(com.ibm.team.workitem.api.common.WorkItemAttributes.STATE);
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
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.
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.
4 other answers
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 https://jazz.net/library/article/634 as a starter.
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 https://jazz.net/library/article/634 as a starter.
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.
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 https://jazz.net/wiki/bin/view/Main/AttributeCustomization 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 (dojo.date.compare(endDate, beginDate) >= 0) {
return Status.OK_STATUS;
} else {
return new Status(Severity[severity], message);
}
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 https://jazz.net/wiki/bin/view/Main/AttributeCustomization 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 (dojo.date.compare(endDate, beginDate) >= 0) {
return Status.OK_STATUS;
} else {
return new Status(Severity[severity], message);
}