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

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.

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

0 votes


Accepted answer

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

0 votes


2 other answers

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




1 vote

Comments

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"); 
         }
       

    }
});
})();

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. 

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?


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 ?


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?

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;
         }
       

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

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

0 votes

Comments

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

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

Question asked: Nov 21 '15, 6:13 a.m.

Question was seen: 2,043 times

Last updated: Nov 28 '15, 1:36 a.m.

Confirmation Cancel Confirm