Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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

0 votes


Accepted answer

Permanent link
I tried but Etat=  workItem.getValue(WorkItemAttributes. STATE is always null
Lawrence . selected this answer as the correct answer

0 votes

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

Permanent link
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 ) ;

0 votes

Comments

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


Permanent link
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

0 votes

Comments

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

0 votes

Comments

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

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 ?

0 votes

Comments

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
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 :
 

0 votes


Permanent link
I can't put the log it is as spam message

0 votes


Permanent link
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.


0 votes

Your answer

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

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,941

Question asked: Apr 07 '16, 11:01 a.m.

Question was seen: 3,050 times

Last updated: Aug 10 '16, 9:42 a.m.

Confirmation Cancel Confirm