It's all about the answers!

Ask a question

Problem getting calculated field to work

Susan Hanson (1.6k2173193) | asked May 01 '13, 3:46 p.m.
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.

(function() {
    dojo.declare("org.example.workitems.providers.CalculatedValueSkeleton", null, {

        getValue: function(attribute, workItem, configuration) {
        return 12;
            var ca1 = workItem.getValue('rfeStackVoters'));
            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 Hanson commented 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                        - Error invoking value provider ''
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)

Accepted answer

permanent link
sam detweiler (12.4k6177201) | answered May 01 '13, 6:14 p.m.
also, ar ca1 = workItem.getValue('rfeStackVoters');

you should use the ID of the attribute.. not its name.

Susan Hanson selected this answer as the correct answer

6 other answers

permanent link
sam detweiler (12.4k6177201) | answered May 20 '13, 7:11 a.m.
you can debug on the web ui with Firebug.

Susan Hanson commented May 20 '13, 7:36 a.m.

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.

sam detweiler commented May 20 '13, 8:06 a.m.

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.

permanent link
Indradri Basu (1.8k1514) | answered May 01 '13, 6:08 p.m.
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.

Susan Hanson commented May 02 '13, 12:15 a.m.

I had looked at that article, and I actually started with the example:


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


Indradri Basu commented May 02 '13, 3:22 a.m.

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.

Susan Hanson commented May 02 '13, 5:43 p.m.

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? 

permanent link
sam detweiler (12.4k6177201) | answered May 02 '13, 6:57 p.m.
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


(function() {
    dojo.declare("com.xx.defect.resolution.Condition", null, {

        matches: function(workItem, configuration)
           var WorkItemAttributes =;
           // default return, means no error
           var rc = false;
           var workitemtype = workItem.getValue(WorkItemAttributes.TYPE);
           // log for debugging
           // in workspace/.metadata/.log

           if( workitemtype ==="defect" )
              var state= workItem.getValue(WorkItemAttributes.STATE);


              if(state === "3" )    // numeric of Sx workitem state
                 var resolution = workItem.getValue(WorkItemAttributes.RESOLUTION);
                 if(resolution === "3" )  /* || resolution === "4"); the numeric of the rx resolution code */
                      // this means error
                      rc = true;                     
           return rc;

Kevin Ramer commented May 03 '13, 4:07 p.m.

Hmmm.   Triple = in your conditionals

if(resolution === "3" )

 .. maybe that's why mine isn't working either.  I'm used to the customary pair.

sam detweiler commented May 03 '13, 5:12 p.m.
var sNum = "55";
var iNum = 55;
alert(sNum == iNum);    //outputs "true"
alert(sNum ==="iNum);   //outputs "false"" (Identically equal)

permanent link
Ralph Schoon (56.6k23642) | answered May 07 '13, 2:38 a.m.
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 Lab 5.

If you have done that, go through 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. 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 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 and to understand the syntax. E.g. use the right quotation marks e.g. getValue("") 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.

Susan Hanson commented May 07 '13, 10:01 a.m.

>>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:

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?

Susan Hanson commented May 07 '13, 10:02 a.m.

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                        - Error invoking value provider ''
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{"Bundle-SymbolicName":"org.dojotoolkit.dojo", "path":"resources\_base\_loader", "name":"loader.js"})

permanent link
Susan Hanson (1.6k2173193) | answered May 20 '13, 3:13 a.m.
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.


permanent link
Ralph Schoon (56.6k23642) | answered May 20 '13, 8:01 a.m.
edited May 20 '13, 8:32 a.m.
 Look into The process Enactment Workshop lab5 at.the end for debugging with Firebug. I personally prefer the Chrome Developer tools to do so.

sam detweiler commented May 20 '13, 8:08 a.m.

good point.. I almost never use Chrome. but its javascript debugger is pretty nice

Your answer

Register or to post your answer.