Problem getting calculated field to work
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
Comments
I'm assuming these are server-side javascripts, so how would I debug them in a client when they are on the server? Also, I'm using the Eclipse client.
I do not think you can interactively debug the javascript functionsl with eclipse.
their design is client neutral, but the debugging requires using the Web UI.
Comments
I had looked at that article, and I actually started with the example:
dojo.provide("org.example.workitems.providers.CalculatedValueSkeleton");(function() { dojo.declare("org.example.workitems.providers.CalculatedValueSkeleton", null, {
getValue: <b><span style="color:#7f0055">function</span></b>(attributeId, workItem, configuration) { <b><span style="color:#7f0055">return</span></b> 42; }
}); })();
So perhaps the (); at the end is really wrong in the example?
I did add a dependency, although I can't even get any indication that the script is actually being run at all.
I've changed to use double-quotes and the ID (rfestackvotes) based on the XML.
Is there a way to determine if my script is being triggered?
Susan
I meant the statement var ca1 = workItem.getValue('rfeStackVoters')); has an extra bracket. You should be able to see the script firing sequence in the .log file which should be in the .metadata folder of your eclipse workspace.
Thanks .... I'm not sure what you mean I can see the firing sequence in the .log file in my eclipse workspace. I assume that this script will be running on the server itself, so that when a work item is saved, this script will run.
I have a test server and have (I thought) uploaded the script via the RTC client to the RTC server (different machine). However, as mentioned, I have done a search through the entire directory structure of my server and I can't actually find the script with the name that I provided in the Attribute Customization.
I think this is also part of my problem ... it seems to me that maybe I need to do something different to get it to run from my server?
Susan
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
Hmmm. Triple = in your conditionals
if(resolution === "3" )
.. maybe that's why mine isn't working either. I'm used to the customary pair.
var sNum = "55";
var iNum = 55;
alert(sNum == iNum); //outputs "true"
alert(sNum ==="iNum); //outputs "false"" (Identically equal)
http://www.java2s.com/Tutorial/JavaScript/0040__Operators/IdenticallyEqualandNotIdenticallyEqual.htm
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
>>One common issue is that you have to enable JavaScript in the server properties. If you don't you will always get an error.
I have already done this and confirmed that it is set to true:
Property Current Value Default Value
Enable Process Attachment Scripts true false
Based on the exception, it looks like it is having problems loading Dojo for these:
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
Does Dojo come with the RTC server by default and if so, why would it be having problems loading dojo? If not, then where does it need to be put into the RTC directory structure such that the server can access it properly?
And i'm pretty sure it is attempting to CALL my script since this is the only value_provider
2013-05-07 09:59:32,087 [ http-bio-9443-exec-47] ERROR com.ibm.team.workitem.common - Error invoking value provider 'com.ibm.team.workitem.valueproviders.VALUE_PROVIDER._4lwvsLHcEeKlOeVMi2AFTA'
org.mozilla.javascript.JavaScriptException: [object Error] ({"Bundle-SymbolicName":"org.dojotoolkit.dojo", "path":"resources\_base\_loader", "name":"loader.js"}#428)
at org.mozilla.javascript.gen.c2._c18({"Bundle-SymbolicName":"org.dojotoolkit.dojo", "path":"resources\_base\_loader", "name":"loader.js"}:427)
at org.mozilla.javascript.gen.c2.call({"Bundle-SymbolicName":"org.dojotoolkit.dojo", "path":"resources\_base\_loader", "name":"loader.js"})
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.Okay, so I was able to figure out that it is throwing an exception when it loads ... does this mean that dojo isn't available? I didnt' see anywhere that indicated I needed to download/install it ... is that what is needed?
2013-05-03 14:59:58,176 [ ccm: AsynchronousTaskRunner-0] ERROR com.ibm.team.workitem.common - Error invoking value provider 'com.ibm.team.workitem.valueproviders.VALUE_PROVIDER._4lwvsLHcEeKlOeVMi2AFTA'
org.mozilla.javascript.JavaScriptException: [object Error] ({"Bundle-SymbolicName":"org.dojotoolkit.dojo", "path":"resources\_base\_loader", "name":"loader.js"}#428)
at org.mozilla.javascript.gen.c2._c18({"Bundle-SymbolicName":"org.dojotoolkit.dojo", "path":"resources\_base\_loader", "name":"loader.js"}:427)