It's all about the answers!

Ask a question

Script to check the status and category attributes


Lorenzo . (59412) | asked Apr 07 '16, 11:01 a.m.
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


permanent link
Laurence Chaptal (1623) | answered Aug 10 '16, 9:11 a.m.
I tried but Etat=  workItem.getValue(WorkItemAttributes. STATE is always null
Lorenzo . selected this answer as the correct answer

Comments
Ralph Schoon commented Aug 10 '16, 9:23 a.m. | edited Aug 10 '16, 9:42 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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



permanent link
Ralph Schoon (63.1k33646) | 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
Ralph Schoon commented Apr 13 '16, 5:33 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Please see https://jazz.net/wiki/bin/view/Main/AttributeCustomization#API_for_Javascript and https://jazz.net/library/article/1093


permanent link
Lorenzo . (59412) | answered May 24 '16, 8:29 a.m.
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
Ralph Schoon commented May 24 '16, 9:05 a.m. | edited May 24 '16, 9:06 a.m.
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

"The customer tried the following script and it is not working "

is not useful information at all, I am afraid.



permanent link
Lorenzo . (59412) | answered May 24 '16, 9:22 a.m.
Ralph, just to clarify. I am merely passing the information i got from that customer as they have no English.

I have not myself created any script nor modified any.

I will advise them again to review the links that you send previously.

Comments
Ralph Schoon commented May 24 '16, 9:30 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

This is not going to work. You can not ask questions for a customer, you have no details, you have no description of the errors, you can't answer any questions. Pointless to try this on a forum.


permanent link
Laurence Chaptal (1623) | answered May 30 '16, 4:49 a.m.

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 ?


Comments
Lorenzo . commented May 30 '16, 4:54 a.m.

Hi Laurence,

Please give us more details.
What is not working exactly and what kind of error you get if any?
Please add any output logs.

Thanks


permanent link
Laurence Chaptal (1623) | answered Jul 05 '16, 10:37 a.m.
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 :
 

permanent link
Laurence Chaptal (1623) | answered Jul 05 '16, 10:39 a.m.
I can't put the log it is as spam message

permanent link
Ralph Schoon (63.1k33646) | 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.FILED_AGAINST);
  var Etat= workItem.getValue(WorkItemAttributes.STATE);
I can only suggest the following:

Read the documentation like https://jazz.net/wiki/bin/view/Main/AttributeCustomization start with a small example.


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.