Script to check the status and category attributes
One of our customer is tring to create a script based on he folliwing Jazz.net entry:
How to validate a customized attribute value using another attribute value?
https://jazz.net/forum/questions/211217/how-to-validate-a-customized-attribute-value-using-another-attribute-value
The script check the status and category attributes (Classé dans) but it does not seems to work...
-----
dojo.provide("org.example.workitems.providers.Validator");
dojo.require("com.ibm.team.workitem.api.common.Category");
dojo.require("com.ibm.team.workitem.api.common.Status");
(function() {
var Category= com.ibm.team.workitem.attribute.category;
var Status= com.ibm.team.workitem.api.common.Status;
var Etat= com.ibm.team.workitem.api.common.state;
dojo.declare("org.example.workitems.providers.Validator", null, {
validate: function(attribute, workItem, configuration) {
var uti = workItem.getValue("utilisation");
console.log("HERE IS Etat VALUE" + " " + Etat);
console.log("HERE IS utilisation VALUE" + " " + uti);
console.log("HERE IS catégorie VALUE" + " " + Category);
if (Etat == 'Enchainement_activites_anomalie.state.s1' && Category != '_6SH7JcjxEeWM1dgCThyTQQ'){
return new Status(Category["ERROR"], "Echec Validation. Merci de renseigner Classé dans");
}
if (Etat =='Enchainement_activites_anomalie.state.s6' && Category !='_6SH7JcjxEeWM1dgCThyTQQ'){
return new Status(Category["ERROR"], "Echec Validation. Merci de renseigner Classé dans");
}
if (etat =='Enchainement_activites_anomalie.state.s5' && Category !='_6SH7JcjxEeWM1dgCThyTQQ'){
return new Status(Category["ERROR"], "Echec Validation. Merci de renseigner Classé dans");
}
if (Etat =='Enchainement_activites_anomalie.state.s11' && Category !='_6SH7JcjxEeWM1dgCThyTQQ'){
return new Status(Category["ERROR"], "Echec Validation. Merci de renseigner Classé dans");
}
if (Etat =='Enchainement_activites_anomalie.state.s2' && (Category =='_6SH7JcjxEeWM1dgCThyTQQ' || Category == '_TCypltcCEeWtAOSAy1FJag')){
return new Status(Category["ERROR"], "Echec Validation. Merci de renseigner Classé dans");
}
if (Etat =='Enchainement_activites_anomalie.state.s3' && (Category =='_6SH7JcjxEeWM1dgCThyTQQ' || Category == '_TCypltcCEeWtAOSAy1FJag')){
return new Status(Category["ERROR"], "Echec Validation. Merci de renseigner Classé dans");
}
if (Etat =='Enchainement_activites_anomalie.state.s4' && (Category =='_6SH7JcjxEeWM1dgCThyTQQ' || Category == '_TCypltcCEeWtAOSAy1FJag')){
return new Status(Category["ERROR"], "Echec Validation. Merci de renseigner Classé dans");
}
return Status.OK_STATUS;
}
});
})();
-----
Can some script person please review the script and pointto possible errrors/changes needed to get it to work?
Thanks very much
Accepted answer
STATE is always null
Comments
Because this is totally wrong:
var Category= com.ibm.team.workitem.attribute.category;
var Status= com.ibm.team.workitem.api.common.Status;
var Etat= com.ibm.team.workitem.api.common.state;
I have hinted on that in several answers and comments below already.
Instead you need (under function)
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
Because otherwise you get null in
var state=workItem.getValue( WorkItemAttributes.STATE ) ;
var category=workItem.getValue( WorkItemAttributes.FILED_AGAINST ) ;
If there are no resources that can follow the guidance in https://jazz.net/wiki/bin/view/Main/AttributeCustomization#API_for_Javascript and https://jazz.net/library/article/1093 (and in the forum answers), then there is no way to use attribute customization. All the hints in the answers below are provided in the documentation behind those links as well.
I am sorry, but you can't expect the forum to fix your scripts if you don't follow the suggestions.
7 other answers
This does nothing:
dojo.require("com.ibm.team.workitem.api.common.Category");
You need
dojo.require("com.ibm.team.workitem.api.common.Severity");
dojo.require("com.ibm.team.workitem.api.common.Status");
You need (under function)
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
In the function you need to read
var state=workItem.getValue(
WorkItemAttributes.STATE
) ;
var category=workItem.getValue(
WorkItemAttributes.FILED_AGAINST
) ;
Comments
Please see https://jazz.net/wiki/bin/view/Main/AttributeCustomization#API_for_Javascript and https://jazz.net/library/article/1093
-----
dojo.provide("org.example.workitems.providers.Validator");
dojo.require("com.ibm.team.workitem.api.common.Severity");
dojo.require("com.ibm.team.workitem.api.common.Status");
(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
var Category= workItem.getValue( WorkItemAttributes.FILED_AGAINST);
var Status= com.ibm.team.workitem.api.common.Status;
var Etat= workItem.getValue(WorkItemAttributes.state);
dojo.declare("org.example.workitems.providers.Validator", null, {
validate: function(attribute, workItem, configuration) {
var uti = workItem.getValue("utilisation");
console.log("HERE IS Etat VALUE" + " " + Etat);
console.log("HERE IS utilisation VALUE" + " " + uti);
console.log("HERE IS catégorie VALUE" + " " + Category);
if (Etat == 'Enchainement_activites_anomalie.state.s1' && Category != '_6SH7JcjxEeWM1dgCThyTQQ'){
return new Status(Category["ERROR"], "Echec Validation. Merci de renseigner Classé dans");
}
if (Etat == 'Enchainement_activites_anomalie.state.s6' && Category != '_6SH7JcjxEeWM1dgCThyTQQ'){
return new Status(Category["ERROR"], "Echec Validation. Merci de renseigner Classé dans");
}
if (etat == 'Enchainement_activites_anomalie.state.s5' && Category != '_6SH7JcjxEeWM1dgCThyTQQ'){
return new Status(Category["ERROR"], "Echec Validation. Merci de renseigner Classé dans");
}
if (Etat == 'Enchainement_activites_anomalie.state.s11' && Category != '_6SH7JcjxEeWM1dgCThyTQQ'){
return new Status(Category["ERROR"], "Echec Validation. Merci de renseigner Classé dans");
}
if (Etat == 'Enchainement_activites_anomalie.state.s2' && (Category == '_6SH7JcjxEeWM1dgCThyTQQ' || Category == '_TCypltcCEeWtAOSAy1FJag')){
return new Status(Category["ERROR"], "Echec Validation. Merci de renseigner Classé dans");
}
if (Etat == 'Enchainement_activites_anomalie.state.s3' && (Category == '_6SH7JcjxEeWM1dgCThyTQQ' || Category == '_TCypltcCEeWtAOSAy1FJag')){
return new Status(Category["ERROR"], "Echec Validation. Merci de renseigner Classé dans");
}
if (Etat == 'Enchainement_activites_anomalie.state.s4' && (Category == '_6SH7JcjxEeWM1dgCThyTQQ' || Category == '_TCypltcCEeWtAOSAy1FJag')){
return new Status(Category["ERROR"], "Echec Validation. Merci de renseigner Classé dans");
}
return Status.OK_STATUS;
}
});
})();
-----
Can someone please review the script and point to possible errors/changes needed to get it to work?
Thanks very much
I have not myself created any script nor modified any.
I will advise them again to review the links that you send previously.
I tried with this script but it's not working
dojo.provide("org.example.workitems.providers.Validator");
dojo.require("com.ibm.team.workitem.api.common.Severity");
dojo.require("com.ibm.team.workitem.api.common.Status");
(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
var Category= workItem.getValue( WorkItemAttributes.FILED_AGAINST);
var Status= com.ibm.team.workitem.api.common.Status;
var Etat= workItem.getValue(WorkItemAttributes.state);
dojo.declare("org.example.workitems.providers.Validator", null, {
validate: function(attribute, workItem, configuration) {
var uti = workItem.getValue("utilisation");
console.log("HERE IS Etat VALUE" + " " + Etat);
console.log("HERE IS utilisation VALUE" + " " + uti);
console.log("HERE IS catégorie VALUE" + " " + Category);
if (Etat == 'Enchainement_activites_anomalie.state.s1' && Category != '_6SH7JcjxEeWM1dgCThyTQQ'){
return new Status(Category["ERROR"], "Echec Validation. Merci de renseigner Classé dans");
}
if (Etat == 'Enchainement_activites_anomalie.state.s6' && Category != '_6SH7JcjxEeWM1dgCThyTQQ'){
return new Status(Category["ERROR"], "Echec Validation. Merci de renseigner Classé dans");
}
if (etat == 'Enchainement_activites_anomalie.state.s5' && Category != '_6SH7JcjxEeWM1dgCThyTQQ'){
return new Status(Category["ERROR"], "Echec Validation. Merci de renseigner Classé dans");
}
if (Etat == 'Enchainement_activites_anomalie.state.s11' && Category != '_6SH7JcjxEeWM1dgCThyTQQ'){
return new Status(Category["ERROR"], "Echec Validation. Merci de renseigner Classé dans");
}
if (Etat == 'Enchainement_activites_anomalie.state.s2' && (Category == '_6SH7JcjxEeWM1dgCThyTQQ' || Category == '_TCypltcCEeWtAOSAy1FJag')){
return new Status(Category["ERROR"], "Echec Validation. Merci de renseigner Classé dans");
}
if (Etat == 'Enchainement_activites_anomalie.state.s3' && (Category == '_6SH7JcjxEeWM1dgCThyTQQ' || Category == '_TCypltcCEeWtAOSAy1FJag')){
return new Status(Category["ERROR"], "Echec Validation. Merci de renseigner Classé dans");
}
if (Etat == 'Enchainement_activites_anomalie.state.s4' && (Category == '_6SH7JcjxEeWM1dgCThyTQQ' || Category == '_TCypltcCEeWtAOSAy1FJag')){
return new Status(Category["ERROR"], "Echec Validation. Merci de renseigner Classé dans");
}
return Status.OK_STATUS;
}
});
})();
Can you help me to see the errors ?
(function() {
var Category= com.ibm.team.workitem.attribute.category;
var Status= com.ibm.team.workitem.api.common.Status;
var Etat= com.ibm.team.workitem.api.common.state;
That does not make any sense to me. I don't know where the code comes from but the code would look like
(function() { var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes; dojo.declare("org.example.workitems.providers.Validator", null, { validate: function(attribute, workItem, configuration) { var Category= workItem.getValue(WorkItemAttributes.I can only suggest the following:FILED_AGAINST
);
var Etat= workItem.getValue(WorkItemAttributes.STATE
);
Read the documentation like https://jazz.net/wiki/bin/view/Main/AttributeCustomization start with a small example.