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

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

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 ();
    }
 }
});
})();
_____________________________________________

0 votes

Comments

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.

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

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.

1 vote

Thanks Donals, Ralph, it works for me now.

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

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

0 votes

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: Apr 12 '16, 5:49 p.m.

Question was seen: 1,986 times

Last updated: Apr 26 '16, 11:48 a.m.

Related questions
Confirmation Cancel Confirm