It's all about the answers!

Ask a question

How to make a shared calculated field read-only in one workitem and writable in other?


Pravin Patil (104142133) | asked Apr 12 '16, 5:49 p.m.
edited Apr 20 '16, 6:52 a.m. by Ralph Schoon (63.2k33646)

I have 2 workitems with id's  "scr" and "sir"

Workitem "scr" has a tab "Test Impact", which has calculated fields "ETC1", "ETC2" etc. The sum of these calculated fields is populated on "Overview" tab of the "scr" workitem in a read-only calculated field called as "ETC" .

"sir" shares the ETC attributes from "scr" and has same structure as "scr" i.e. "Team Impact" tab, "ETC1", "ETC2" etc. The sum of these calculated fields is populated on "Overview" tab of the "sir" workitem in a read only field called as "ETC".
But recently we had to remove "Team Impact" tab from "sir". Also the "ETC" field on overview tab was made writable in "sir" only. But the ETC turns to zero (0) on save. Looks like even though I removed "Team Impact" tab from "sir", the calculated "ETC" runs the scripts on save thus turning the ETC value to 0.

The requirement is to retain single ETC field in scr and sir, but should be writable in sir and auto-calculated in scr.

Below is the ETC calculated script.
It works correctly, but alert in "else" doesnt show anything. So not sure what is happening. Is this script running properly? Can you help me understand whats wrong with this script?
_____________________________________________
dojo.provide("example.calculated.sumALL");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");

(function() {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("example.calculated.sumALL", null, {
    getValue: function(attributeId, workItem, configuration) {
 var wit =  workItem.getValue(WorkItemAttributes.TYPE);
 if (wit == "scr")
 {
           var  ca1 = parseInt(workItem.getValue('batch_interfaces_etc_total'));
            var  ca2 = parseInt(workItem.getValue('calheers_etc_total'));
            var  ca3 = parseInt(workItem.getValue('correspondence_etc_total'));
            var  ca4 = parseInt(workItem.getValue('dba_etc_total'));
            var  ca5 = parseInt(workItem.getValue('eligibility_etc_total'));
            var  ca6 = parseInt(workItem.getValue('fiscal_etc_total'));
            var  ca7 = parseInt(workItem.getValue('imaging_etc_total'));
            var  ca8 = parseInt(workItem.getValue('ivr.cc_etc_total'));
            var  ca9 = parseInt(workItem.getValue('noa_etc_total'));
//         var  ca10 = parseInt(workItem.getValue('online_etc_total'));
            var  ca11 = parseInt(workItem.getValue('performance_etc_total'));
            var  ca12 = parseInt(workItem.getValue('reports_etc_total'));
            var  ca13 = parseInt(workItem.getValue('system_test_etc_total'));
            var  ca14 = parseInt(workItem.getValue('tech_arch_etc_total'));
            var  ca15 = parseInt(workItem.getValue('tech_ops_etc_total'));
            var  ca16 = parseInt(workItem.getValue('training_etc_total'));
            var  ca17 = parseInt(workItem.getValue('security_etc_total'));
            var  ca18 = parseInt(workItem.getValue('test_support_etc_total'));
            var  ca19 = parseInt(workItem.getValue('case_management_total'));
            var  ca20 = parseInt(workItem.getValue('customer_management_etc_total'));
            return  ca1 + ca2 + ca3 + ca4 + ca5 + ca6 + ca7 + ca8 + ca9 + ca11 + ca12 + ca13 + ca14 + ca15 + ca16 + ca17 + ca18  + ca19 + ca20;
    }
    else {
    alert ("sir");
//    return ();
    }
 }
});
})();
_____________________________________________


Comments
Donald Nong commented Apr 12 '16, 9:20 p.m.

Using alert() for debugging is a bad idea. Stick with console.log(). Note that the script may be executed on the server side and alert() would give you nothing.


Ralph Schoon commented Apr 13 '16, 2:05 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

SCR and SIR are no valid work item ID's. A work item ID would be 12345.


1
Ralph Schoon commented Apr 13 '16, 5:15 a.m. | edited Apr 13 '16, 5:16 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

The else case is syntactically incorrect the script is a function and it must return a value. A function can no not return a value. You could read the current value of that attribute and return the same value.


Pravin Patil commented Apr 19 '16, 8:19 p.m. | edited Apr 20 '16, 6:43 a.m.

Thanks Donals, Ralph, it works for me now.


Ralph Schoon commented Apr 20 '16, 2:17 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Can you to the benefit of all forum members

  • Explain what you did to fix the script
  • Post the result

Do it in an answer so I can accept it.

Accepted answer


permanent link
Pravin Patil (104142133) | answered Apr 26 '16, 11:48 a.m.

Within "else" I returned value that gets entered in the ETC field. So the final code is as below.

_______

dojo.provide("example.calculated.sumALL");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");

(function() {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("example.calculated.sumALL", null, {
    getValue: function(attributeId, workItem, configuration) {
    //console.log("here");
var wit =  workItem.getValue(WorkItemAttributes.TYPE);
if (wit == "scr")
{
            var  ca1 = parseInt(workItem.getValue('batch_etc_total'));
            var  ca4 = parseInt(workItem.getValue('dba_etc_total'));
            var  ca5 = parseInt(workItem.getValue('eli_etc_total'));
            
            return  ca1 + ca4 + ca5;
    }
    else {
var  etcvalue = parseInt(workItem.getValue('etc_00'));
    //alert ("");
    return etcvalue;
    }
}
});
})();

______

Ralph Schoon selected this answer as the correct answer

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.