Script to check the status and category attributes
![]()
Hi,
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
![]()
I tried but Etat= workItem.getValue(WorkItemAttributes.
STATE is always null
Lorenzo . selected this answer as the correct answer
Comments ![]() FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Because this is totally wrong:
|
7 other answers
![]()
Ralph Schoon (62.7k●3●36●43)
| answered Apr 13 '16, 5:32 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
I would consider to actually read the category, status and the other values needed in the comparison. If you actually have values other than nothing, the comparison might work.
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
|
![]()
The customer tried the following script and it is 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 someone please review the script and point to possible errors/changes needed to get it to work? Thanks very much Comments ![]() FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
You want someone else to spend time on adopting a custom script to their process and debug it for you? I don't think that is going to happen especially since
|
![]()
Hi Lorenzo,
I created a workitem with category 'Consult' and there's no message, the state is null but it should be 'Nouvelle' in the log there is : |
![]() I can't put the log it is as spam message |
![]()
Ralph Schoon (62.7k●3●36●43)
| answered Jul 05 '16, 11:16 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
The original script
(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: Read the documentation like https://jazz.net/wiki/bin/view/Main/AttributeCustomization start with a small example. |