It's all about the answers!

Ask a question

Set automatically enum literal using Calculated Value script


Veronica Alvarado (116) | asked Aug 22 '18, 7:35 p.m.
edited Aug 22 '18, 7:42 p.m.
Hello,

I'm trying to set automatically an "Unassigned" literal in my Application enum if work item status is "Failed". When I move to Failed status, ID literal is add as new value in the enum.

This is the script that I have created:

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:


In my Application attribute, I assigned my script and status attribute as dependency.

Can you help me to know if I need to configure any ?

Thanks for your help.

2 answers



permanent link
Ralph Schoon (63.1k33646) | answered Aug 23 '18, 3:00 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
  1. There is no real question in your question. What is the question?
  2. The line: return workItem.getValue("testAttribute.application); is missing a closing apostrophe.
  3. 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. 

permanent link
Veronica Alvarado (116) | answered Aug 23 '18, 7:21 p.m.

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

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.