Why is my script-based calculated value causing the Filed Against value to reset to Unassigned every time I hit Save?
Michael Walker (992●15●201●157)
| asked Mar 26 '13, 1:10 a.m.
edited Mar 26 '13, 3:21 a.m. by Ralph Schoon (63.5k●3●36●46)
I'm trying to create a script-based calculated value that will set the Filed Against value when the Status is in a specific state. I can get this to work if I programatically set the Filed Against to a value in the script.
However, I don't want to do this in the final script so user's can change the Filed Against to whatever they want in other states. The problem when I use the script below is everytime I save a work item it changes the File Against value back to Unassigned, which is the default value. This occurs even when I specifically set the Filed Against value to something else before hitting Save. My goal is it will only automatically set the Filed Against value when in a specific state. Otherwise it stays what the user sets it to. Dependencies are project area, status, and type. Any ideas why my script below is causing the Filed Against to reset back to Unassigned? dojo.provide("org.example.Awards_Test"); dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes"); (function() { var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes; dojo.declare("org.example.Awards_Test", null, { getValue: function(attributeId, workItem, configuration) { var unassigned = "_mlNToHhdEeK0VvmfhffD_w"; var swg = "_mv6u1HhdEeK0VvmfhffD_w"; var swgInfo = "_WcavgHh7EeKkT71PvOj-dQ"; var swgMDM = "_XTrusHh7EeKkT71PvOj-dQ"; //var filed = workItem.getValue(WorkItemAttributes.FILED_AGAINST); //console.log("filed: " + filed); var state = workItem.getValue(WorkItemAttributes.STATE); console.log("state: " + state); var newFiled; if (workItem.getValue(WorkItemAttributes.TYPE) === "com.ibm.team.apt.workItemType.epic" && workItem.getValue(WorkItemAttributes.STATE) === "awared.state.s3") { if (workItem.getValue(WorkItemAttributes.FILED_AGAINST) === swg) { console.log("swg"); newFiled = swgInfo; return newFiled ; } else if (workItem.getValue(WorkItemAttributes.FILED_AGAINST) === swgInfo) { console.log("swgInfo"); newFiled = swgMDM; return newFiled ; } else { return Status.OK_STATUS; } } }}); })(); |
Accepted answer
Ralph Schoon (63.5k●3●36●46)
| answered Mar 27 '13, 5:46 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
This script worked for me at least in the tests I did in 4.0.1. It triggers against Type, State and Filed Against as dependencies.
/******************************************************************************* * Licensed Materials - Property of IBM * (c) Copyright IBM Corporation 2011. All Rights Reserved. * * CategoryAttributeValueAnalyzer * * Note to U.S. Government Users Restricted Rights: * Use, duplication or disclosure restricted by GSA ADP Schedule * Contract with IBM Corp. *******************************************************************************/ dojo.provide("com.acme.providers.script.CategoryAttributeValueAnalyzer"); dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes"); dojo.require("dojo.date"); dojo.require("dojo.date.stamp"); (function() { var doDebug = true; var scriptname = "CategoryAttributeValueAnalyzer"; var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes; dojo.declare("com.acme.providers.script.CategoryAttributeValueAnalyzer", null, { getValue: function(attributeId, workItem, configuration) { debug("- Start"); var type = workItem.getValue(WorkItemAttributes.TYPE); debug("Type: " + type); var category = workItem.getValue(WorkItemAttributes.FILED_AGAINST); debug("Filed Against: " + category); var state = workItem.getValue(WorkItemAttributes.STATE); debug("State: " + state); if(state=="3"){ if(type=="defect"){ return "_NOjVq3T1EeK_I-am-aV--w"; } } return category; function debug(display){ if(doDebug){ console.log(scriptname + " " + display); } } } }); })(); Michael Walker selected this answer as the correct answer
Comments
Michael Walker
commented Mar 28 '13, 1:27 a.m.
Thank you for the information Ralph. We'll be using a work item template to set the Filed Against initially along with other fields. My script seems to work and correctly set the Filed Against value based on the State.
|
4 other answers
Ralph Schoon (63.5k●3●36●46)
| answered Mar 26 '13, 3:29 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Michael,
one thing that is very disturbing in the code above is the line return Status.OK_STATUS; This line does not make sense at all. A calculated value provider always returns the value of the calculation. If the value should not change, it returns the old value. Status if for validations or conditions. Another thing to mention is that calculated attributes should typically be read only. More examples and background can be found here: https://jazz.net/library/article/1093 Lab 5. Without knowing the background, the filed against attribute is something that I would typically not touch myself in an automation. Comments
Michael Walker
commented Mar 26 '13, 2:52 p.m.
Ralph,
Michael Walker
commented Mar 26 '13, 2:54 p.m.
(continued) back to "Unassigned". With the Status and Owner fields it would populate the variables with the new values at Save. It only works if I hardcode the variable in the script with one of the Filed Against values.
|
Hi Michael,
Instead of just declaring the variable newFiled without any value.
You can set:
var newFiled = workItem.getValue(WorkItemAttributes.FILED_AGAINST);
and in the last line you can just return newFiled.
else {
return newFiled ; }
Hope this helps you.
Comments
Michael Walker
commented Mar 26 '13, 2:58 p.m.
Abuzaid,
Abuzaid Shaikh
commented Mar 27 '13, 4:07 a.m.
Hi Michael,
Can you use
var filed = workItem.getValue("com.ibm.team.workitem.attribute.category");
console.log("Filed: "+ filed);
and see what value it returns when you change the value.
|
looks like a bug in the script processor passing the oldstate filed_against, instead of the newstate value
Comments
Michael Walker
commented Mar 26 '13, 5:48 p.m.
I tried a simple script that would show the variable values in the eclipse log. After opening a work item and saving it, I went back in and changed the Filed Against value and the Status value. The log showed the Status variable changed to the new value, but the Filed Against value kept the old value.
|
Ralph Schoon (63.5k●3●36●46)
| answered Mar 27 '13, 4:41 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER edited Mar 27 '13, 4:50 a.m.
I used the script below as calculated value (for description as described in the Process Enactment Workshop). It triggers against Type, State and Filed Against as dependencies. And it seems to be working for me. At least it shows the changed category as soon as I change it. Please be aware that the state change becomes not active immediately, other than the category change. The state becomes active after the save was processed.
This was on RTC 4.0.1. /******************************************************************************* * Licensed Materials - Property of IBM * (c) Copyright IBM Corporation 2011. All Rights Reserved. * * Note to U.S. Government Users Restricted Rights: * Use, duplication or disclosure restricted by GSA ADP Schedule * Contract with IBM Corp. *******************************************************************************/ dojo.provide("com.acme.providers.script.AttributeValueAnalyzer"); dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes"); dojo.require("dojo.date"); dojo.require("dojo.date.stamp"); (function() { var doDebug = true; var scriptname = "AttributeValueAnalyzer"; var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes; dojo.declare("com.acme.providers.script.AttributeValueAnalyzer", null, { getValue: function(attributeId, workItem, configuration) { debug("- Start"); var out = "Attribute Values:\n"; out+=getAttributeData("ID: ", WorkItemAttributes.ID); out+=getAttributeData("TYPE: ", WorkItemAttributes.TYPE); out+=getAttributeData("Project Area: ", WorkItemAttributes.PROJECT_AREA); out+=getAttributeData("Filed Against: ", WorkItemAttributes.FILED_AGAINST); out+=getAttributeData("State: ", WorkItemAttributes.STATE); out+="\nCustom:\n"; return out; function debug(display){ if(doDebug){ console.log(scriptname + " " + display); } } function getAttributeData (message,attributeID){ debug("Get Attribute Data for " + attributeID); var isSet=""; var attributeValue=""; var attributeLabel=""; var result = message + "\n"; try{ isSet=workItem.isAttributeSet(attributeID); attributeValue=workItem.getValue(attributeID); } catch (e) { attributeValue = "Exception reading the attribute value"; } try{ attributeLabel=workItem.getLabel(attributeID); } catch (e) { attributeLabel= "Exception reading the attribute label:" + e.toLocaleString(); } result +="Set: " + isSet + "\nValue= " + attributeValue + "\nLabel= " + attributeLabel; debug(result); return result + "\n\n"; } } }); })(); |
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.