Problem getting calculated field to work
I am attempting to add in a calculated field into a work item and can't seem to find a way to get it even to (i don't think) even to run my script.
In the Attribute Customization, I created a new calculated Value and set the local file path to the JS file that I have:
/*******************************************************************************
* 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("org.example.workitems.providers.CalculatedValueSkeleton");
(function() {
dojo.declare("org.example.workitems.providers.CalculatedValueSkeleton", null, {
getValue: function(attribute, workItem, configuration) {
return 12;
var ca1 = workItem.getValue('rfeStackVoters'));
console.log(ca1);
if (ca1.length > 0) return 20;
else return 1;
}
});
})();
As you can see, I have been attempting to get the value of a custom property but then went to just hardcoding it to return 12 so that I can at least see that it works.
I have sent script enablement on my server. Then I add an Integer attribute into my work item and show it (read-only) on the editor.
WHen I go to create a new work item type, the field shows (read-only) a 0. When I save, it remains 0, reload the work item, still 0.
I also went to try to find the actual JS script on the server, since I assumed it would be uploaded from my local to the server, and I did not find the JS file anywhere.
Any pointers or help?
Susan
In the Attribute Customization, I created a new calculated Value and set the local file path to the JS file that I have:
/*******************************************************************************
* 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("org.example.workitems.providers.CalculatedValueSkeleton");
(function() {
dojo.declare("org.example.workitems.providers.CalculatedValueSkeleton", null, {
getValue: function(attribute, workItem, configuration) {
return 12;
var ca1 = workItem.getValue('rfeStackVoters'));
console.log(ca1);
if (ca1.length > 0) return 20;
else return 1;
}
});
})();
As you can see, I have been attempting to get the value of a custom property but then went to just hardcoding it to return 12 so that I can at least see that it works.
I have sent script enablement on my server. Then I add an Integer attribute into my work item and show it (read-only) on the editor.
WHen I go to create a new work item type, the field shows (read-only) a 0. When I save, it remains 0, reload the work item, still 0.
I also went to try to find the actual JS script on the server, since I assumed it would be uploaded from my local to the server, and I did not find the JS file anywhere.
Any pointers or help?
Susan
Accepted answer
6 other answers
you can debug on the web ui with Firebug.
Comments
Hi Susan, just a quick look tells me that your code have errors. The getvalue() function should not end with 2 brackets. Preferably use double quotes for the attribute id and add a dependency attribute (which you haven't mentioned) changing which your script should fire and makes your job much easier. See Work Item attribute customization for further reference.
Comments
everything is stored in the database.. not on the local fileystem
here is one of my conditionals.. note the console.log() function which will write to ccm.log on the server
<code>
dojo.provide("com.xx.defect.resolution.Condition");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
dojo.declare("com.xx.defect.resolution.Condition", null, {
matches: function(workItem, configuration)
{
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
// default return, means no error
var rc = false;
var workitemtype = workItem.getValue(WorkItemAttributes.TYPE);
// log for debugging
// in workspace/.metadata/.log
console.log(workitemtype);
if( workitemtype ==="defect" )
{
var state= workItem.getValue(WorkItemAttributes.STATE);
//console.log(state);
if(state === "3" ) // numeric of Sx workitem state
{
var resolution = workItem.getValue(WorkItemAttributes.RESOLUTION);
//console.log(resolution);
if(resolution === "3" ) /* || resolution === "4"); the numeric of the rx resolution code */
{
// this means error
rc = true;
}
}
}
return rc;
}
});
})();
</code>
here is one of my conditionals.. note the console.log() function which will write to ccm.log on the server
<code>
dojo.provide("com.xx.defect.resolution.Condition");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
dojo.declare("com.xx.defect.resolution.Condition", null, {
matches: function(workItem, configuration)
{
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
// default return, means no error
var rc = false;
var workitemtype = workItem.getValue(WorkItemAttributes.TYPE);
// log for debugging
// in workspace/.metadata/.log
console.log(workitemtype);
if( workitemtype ==="defect" )
{
var state= workItem.getValue(WorkItemAttributes.STATE);
//console.log(state);
if(state === "3" ) // numeric of Sx workitem state
{
var resolution = workItem.getValue(WorkItemAttributes.RESOLUTION);
//console.log(resolution);
if(resolution === "3" ) /* || resolution === "4"); the numeric of the rx resolution code */
{
// this means error
rc = true;
}
}
}
return rc;
}
});
})();
</code>
Comments
One common issue is that you have to enable JavaScript in the server properties. If you don't you will always get an error. See https://jazz.net/library/article/1093 Lab 5.
If you have done that, go through https://jazz.net/library/article/1093 and run some basic examples and get yourself accustomed to the weird looking format. Download the examples in the Eclipse IDE. The have always worked for me.
https://jazz.net/library/article/1093 shows some format conversions. You can't just return arbitrary data in your scripts and expect them to work.
Be aware that there is limited support for complex data types as described in https://jazz.net/library/article/1093 Lab 5.
Add the JavaScript editor to Eclipse to at least avoid the most basic issues.
Make yourself familiar with debugging scripts and understand where the logs are located (Client and Server log).
Make sure to check dependencies for other attributes you need in the work item attribute configuration.
Upload changes and close all open work items you test. Reopen the work items to fetch the new script version.
Make sure to follow the guidance in https://jazz.net/wiki/bin/view/Main/AttributeCustomization and https://jazz.net/library/article/1093 to understand the syntax. E.g. use the right quotation marks e.g. getValue("my.attribute.id") and the like.
Go slow, step by step while developing. Use the debugger or logging. JavaScript (from my perspective) throws you back to the good old times of 9" floppy disks, printf and barely a debugger for embedded development.
If you have done that, go through https://jazz.net/library/article/1093 and run some basic examples and get yourself accustomed to the weird looking format. Download the examples in the Eclipse IDE. The have always worked for me.
https://jazz.net/library/article/1093 shows some format conversions. You can't just return arbitrary data in your scripts and expect them to work.
Be aware that there is limited support for complex data types as described in https://jazz.net/library/article/1093 Lab 5.
Add the JavaScript editor to Eclipse to at least avoid the most basic issues.
Make yourself familiar with debugging scripts and understand where the logs are located (Client and Server log).
Make sure to check dependencies for other attributes you need in the work item attribute configuration.
Upload changes and close all open work items you test. Reopen the work items to fetch the new script version.
Make sure to follow the guidance in https://jazz.net/wiki/bin/view/Main/AttributeCustomization and https://jazz.net/library/article/1093 to understand the syntax. E.g. use the right quotation marks e.g. getValue("my.attribute.id") and the like.
Go slow, step by step while developing. Use the debugger or logging. JavaScript (from my perspective) throws you back to the good old times of 9" floppy disks, printf and barely a debugger for embedded development.
Comments
So, I have gotten this to work. I had to re-install my server a couple times to keep errors from occurring, and then changed the script to use just one ), plus double-quotes, plus the ID.
I do have one final thing ... how can I debug things in these scripts? I tried console.log("write this"); but I didn't find that printed in any of the logs. I also tried just the normal System.out.println() but nothing there either.
Susan
I do have one final thing ... how can I debug things in these scripts? I tried console.log("write this"); but I didn't find that printed in any of the logs. I also tried just the normal System.out.println() but nothing there either.
Susan
Comments
Susan Hanson
May 03 '13, 3:05 p.m.