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

Why is my script-based calculated value causing the Filed Against value to reset to Unassigned every time I hit Save?

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;
}




}
}});
})();

0 votes


Accepted answer

Permanent link
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

0 votes

Comments

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. 

I also implemented a script against State so when the Filed Against and State reach certain values, it will change both the Filed Against and State during same Save action.

The team we're supporting wants to track Awards through RTC and have a state called Promoted that will move the Award up a level and reset the workflow to Submitted.


4 other answers

Permanent link
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. 

1 vote

Comments

Ralph,

The line return Status.OK_STATUS; I added in during my latest test before posting because previous attempts were failing to return what I desired.  I had used this line in previous scripts when dealing with changing Owners based on specific States and wanted to try it to see if it would prevent the Filed Against from resetting. I knew it was a long shot and understand it shouldn't be there.

What I'm noticing is Filed Against behaves differently from the other fields like Status and Owner.  When I set a variable to workItem.getValue(WorkItemAttributes.FILED_AGAINST); and then return the variable at the end it's returning the previous Filed Against value.

For example, user modifies a Work Item and changes Filed Against from "Unassigned" to "Team A".  When I hit Save and the script fires the variable is set to "Unassigned" and thus reverts the Filed Against value from "Team A"

(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.

If I could get it to store the new value for Filed Against my issue would be solved and I could have it modify the Filed Against when a certain Status is achieved.


Permanent link
 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.

1 vote

Comments

Abuzaid,

I had tried that initially but it returns the old Filed Against value and not the new one.

For example, when the script is enabled if I access a Work Item and change the File Against from "Unassigned" to "Team A" and then hit Save the variable is populated with "Unassigned" rather than the new value "Team A".

This is different than with other fields like Status and Owner.  With those if I do :
var state = workItem.getValue(WorkItemAttributes.STATE);
console.log("state: " + state);

and in the Work Item I change the State from Open to Working the variable will be populated with Working in the script after I hit Save.  I need it to store the new value.

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.




Permanent link
looks like a bug in the script processor passing the oldstate filed_against, instead of the newstate value

0 votes

Comments

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. 

Currently it would require me to hardcode a Filed Against value in the variable to get it to work.



var state = workItem.getValue(WorkItemAttributes.STATE);
     
    var type = workItem.getValue(WorkItemAttributes.TYPE);
     
     
    var filed = workItem.getValue(WorkItemAttributes.FILED_AGAINST);

     
    console.log("filed: " + filed);
    console.log("Type: " + type);
    console.log("State: " + state);


Permanent link
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";
    	}
    }
});
})();

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
× 10,937

Question asked: Mar 26 '13, 1:10 a.m.

Question was seen: 7,929 times

Last updated: Mar 28 '13, 1:27 a.m.

Confirmation Cancel Confirm