Set automatically enum literal using Calculated Value script
dojo.provide("org.example.ClearOnValue"); dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes"); (function() { var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes; dojo.declare("org.example.ClearOnValue", null, {
getValue: function(attributeId, workItem, configuration) {
try{
var state= workItem.getValue(WorkItemAttributes.STATE);
if (state == "bugzillaWorkflow.state.s10") // State ID
return "com.sw.att.pc.enum.application.literal.l2"; // Literal ID for Unassigned value
}
// else return the selected value
return workItem.getValue("testAttribute.application);
}
catch(err) {
console.log("Error ClearOnValue: " + err.message);
}
}
});
})();
I have review the following links:
2 answers
- There is no real question in your question. What is the question?
- The line: return workItem.getValue("testAttribute.application); is missing a closing apostrophe.
- Scripts can only read the current state. They can not determine a state change, so your script will only ever do anything after you save a state change.
Hi Ralph,
Thanks for your reply.
I review all the lines into my script and I had these errors:
1. As you commented, I added the closing apostrophe in this line:
return workItem.getValue("testAttribute.application");
2. I put a wrong ID for "Unassigned" literal.
Before:
if (state == "bugzillaWorkflow.state.s10") {
return "com.sw.att.pc.enum.application.literal.l2";
}
After:
if (state == "bugzillaWorkflow.state.s10") {
return "com.sw.att.pc.enum.applicacion.literal.l8";
}
My question was why the returned literal (ID) was being added as a new literal. This was happening because the ID was wrong for “Unassigned” value.
Thanks for your help.
Regards