It's all about the answers!

Ask a question

For all stories where the ASCA Required attribute = Yes, the story should not be allowed to move to the Ready For Production state unless the ASCA Certification attribute = Yes.This is the condition for which i should code.


venkata suvidya dega (266) | asked Nov 21 '15, 6:13 a.m.
dojo.provide("org.example.workitems.providers.AscaCheck");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");

(function() {
     var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
     var scriptname = "AscaCheck";
     dojo.declare("org.example.workitems.providers.AscaCheck", null, {
      matches: function(workItem, configuration) {
      var type =  workItem.getValue(WorkItemAttributes.TYPE);
      var ascareq =  workItem.getValue("ierp.ascarequired");
      var state =  workItem.getValue(WorkItemAttributes.STATE);
      var ascacert = workItem.getValue("ierp.ascacertification");
     
      if((type == "com.ibm.team.apt.workItemType.story") && (state == "ierp.userstoryworkflow.state.s9") &&(ascareq== "iERPYesNo.literal.l5"))
{
      ascacert = "iERPYesNo.literal.l5";
  }
return  ascacert;
}
  });
})();

can anyone pls check this code and tell me if anything wrong as this is not working for me.

Thanks in advance!!!
    

Accepted answer


permanent link
venkata suvidya dega (266) | answered Nov 25 '15, 4:47 a.m.
The code is working fine now.By mistake,i kept semicolon after the if statement in the previous code.

dojo.provide("com.example.Validator.AscaCheck");

dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
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 Severity = com.ibm.team.workitem.api.common.Severity;
        var Status = com.ibm.team.workitem.api.common.Status;

        var scriptname = "AscaCheck";
       
        dojo.declare("com.example.Validator.AscaCheck", null, {

        validate: function(attributeId, workItem, configuration) {
       
        var type =  workItem.getValue(WorkItemAttributes.TYPE);
                               
        var ascareq =  workItem.getValue("ierp.ascarequired");

        var state =  workItem.getValue(WorkItemAttributes.STATE);
       
        var ascacert = workItem.getValue("ierp.ascacertification");

      
      
      
        if((type == "com.ibm.team.apt.workItemType.story") && (state == "ierp.userstoryworkflow.state.s4") &&(ascareq == "iERPYesNo.literal.l5"))
         { 
           if(ascacert == "iERPYesNo.literal.l5")
            {
 
            return Status.OK_STATUS;
             }
            else
              {
               return new Status(Severity["ERROR"], "Yes not selected in ASCA Certification attribute");
               }
     
         } else{
          return  Status.OK_STATUS;
         }
       
        console.log("success"); 
    }
});
})();



Thanks Anup a lot!!!




Ralph Schoon selected this answer as the correct answer

2 other answers



permanent link
Ralph Schoon (63.3k33646) | answered Nov 24 '15, 11:28 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Nov 24 '15, 1:51 p.m.
 First of all, I would suggest to read Process Enactment Workshop for the Rational solution for Collaborative Lifecycle Management Lab 4 and 5 to understand what conditions do.

When this is out of the way, you understand that a condition itself does nothing. It only works with operational behavior:

  • Required for condition
  • Read Only for condition
Preventing a state change is not on the list.

If you want to do something like that, you need to do it in Java using an Advisor. Here is an example: https://rsjazz.wordpress.com/2014/05/26/only-owner-can-close-workitem-advisor/ the code can be enhanced to do what you want.

Comments
Ralph Schoon commented Nov 24 '15, 1:51 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Or you require an attribute that can not be set in the condition and confuse the heck out of the users.


permanent link
anup Gaur (1392444) | answered Nov 22 '15, 3:12 p.m.
 This code looks like something you will use in the calculated value. You should use the validator Attribute customization.
pseudo code given below:

if((type == "com.ibm.team.apt.workItemType.story") && (state == "ierp.userstoryworkflow.state.s9") &&(ascareq== "iERPYesNo.literal.l5")) 
      return Status.OK_STATUS;; 
  } else{
return new Status(Severity["ERROR"], "Yes not selected in ASCA Certification attribute"); 

Please look at :
https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Script_Based_Validation

Best of Lucks!





Comments
venkata suvidya dega commented Nov 23 '15, 9:27 a.m. | edited Nov 28 '15, 1:35 a.m.

Hi Anup,

I have used validator attribute customization and implemented the code below.But it is not working.I am not able to see in the log also.Should we configure anything in Team configuration besides adding the script in project configuration?

dojo.provide("org.example.workitems.providers.AscaCheck");

dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
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 Severity = com.ibm.team.workitem.api.common.Severity;
        var Status = com.ibm.team.workitem.api.common.Status;

        var scriptname = "AscaCheck";
       
        dojo.declare("org.example.workitems.providers.AscaCheck", null, {

        validate: function(attributeId, workItem, configuration) {
       
        var type =  workItem.getValue(WorkItemAttributes.TYPE);
                               
        var ascareq =  workItem.getValue("ierp.ascarequired");

        var state =  workItem.getValue(WorkItemAttributes.STATE);
       
        var ascacert = workItem.getValue("ierp.ascacertification");

       console.log("success");
      
      
        if((type == "com.ibm.team.apt.workItemType.story") && (state == "ierp.userstoryworkflow.state.s9") &&(ascareq== "iERPYesNo.literal.l5")) 
         { 
          return Status.OK_STATUS;
         } else{
          return new Status(Severity["ERROR"], "Yes not selected in ASCA Certification attribute"); 
         }
       

    }
});
})();


anup Gaur commented Nov 23 '15, 1:04 p.m. | edited Nov 23 '15, 1:08 p.m.
Hi Venkat,
I number of things can go wrong here although the code looks ok here. Basic things to check:
1) Please make sure attribute Validation Pre-Condition is enabled in your Operation behavior. 
2) The validation script is applied to the ASCA Certification attribute.
3) The attribute itself may need to be made dependent to the Status attribute. 
4) the attribute ids used are correct. They are case sensitive. 
5) use the console log in several different places to see if the code is reachable. 
Thats how I debug.
Console.log("Success")
Is this line output visible in the .log file? 
6) Make sure scripting itself is enabled in the server. 

venkata suvidya dega commented Nov 24 '15, 5:02 a.m. | edited Nov 28 '15, 1:36 a.m.

Hi Anup,

i checked all the things mentioned by you.The first one,attribute Validation Pre-Condition is not enabled in operation behavior.when i am trying to add it,It is showing that no specific configuration options.so,where should i enable this?



anup Gaur commented Nov 24 '15, 5:40 a.m.

Make sure attribute Validation is selected. and Save.

",It is showing that no specific configuration options" this is fine. This is how it should be.

Are you able to see the console.log output ?



venkata suvidya dega commented Nov 24 '15, 8:06 a.m. | edited Nov 28 '15, 1:36 a.m.

I am not able to see console.log output.But the code is working fine to some extent.It is not allowing me to go to next state even though i am selecting "yes" for Asca certification attribute.so,where should i configure that value to that attribute?


venkata suvidya dega commented Nov 24 '15, 10:11 a.m. | edited Nov 28 '15, 1:36 a.m.

can we use nested if condition like this-


        if((type == "com.ibm.team.apt.workItemType.story") && (state == "ierp.userstoryworkflow.state.s4") &&(ascareq == "iERPYesNo.literal.l5"));
         { 
           if(ascacert == "iERPYesNo.literal.l5");
            {
 
            return Status.OK_STATUS;
             }
            else
              {
               return new Status(Severity["ERROR"], "Yes not selected in ASCA Certification attribute");
               }
     
         } else{
          return  Status.OK_STATUS;
         }
       


anup Gaur commented Nov 24 '15, 10:41 a.m.
You can have as many levels you would like to nest. Looking at the logic :

// test for condition If sate NOT in - Ready For Production - Notice state  != condition
if((type == "com.ibm.team.apt.workItemType.story") && (state != "ierp.userstoryworkflow.state.s9"))  
{  
return Status.OK_STATUS;
}
// test for condition If sate in - Ready For Production and Attribute ASCA has correct value
 if((type == "com.ibm.team.apt.workItemType.story") && (state == "ierp.userstoryworkflow.state.s9") &&(ascareq== "iERPYesNo.literal.l5"))  
{ return Status.OK_STATUS; 
}
else
        return new Status(Severity["ERROR"], "Yes not selected in ASCA Certification attribute");  
// The above code can be written in other ways too - This is just a sample
showing 5 of 7 show 2 more comments

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.