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 ();
}
}
});
})();
_____________________________________________
Accepted answer
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;
}
}
});
})();
______
Comments
Donald Nong
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
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER Apr 13 '16, 2:05 a.m.SCR and SIR are no valid work item ID's. A work item ID would be 12345.
Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER Apr 13 '16, 5:16 a.m.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
Pravin Patil
Apr 20 '16, 6:43 a.m.Thanks Donals, Ralph, it works for me now.
Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER Apr 20 '16, 2:17 a.m.Can you to the benefit of all forum members
Do it in an answer so I can accept it.