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.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
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!!!
2 other answers
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 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.
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;
}
- Required for condition
- Read Only for condition