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 |
Accepted answer
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
you can debug on the web ui with Firebug.
Comments
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.
|
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
Susan Hanson
commented May 02 '13, 12:15 a.m.
I had looked at that article, and I actually started with the example:
dojo.provide("org.example.workitems.providers.CalculatedValueSkeleton");
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.
|
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> Comments
Kevin Ramer
commented May 03 '13, 4:07 p.m.
Hmmm. Triple = in your conditionals
sam detweiler
commented May 03 '13, 5:12 p.m.
var sNum = "55";
|
Ralph Schoon (63.7k●3●36●48)
| answered May 07 '13, 2:38 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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. Comments
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.
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
|
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 |
Ralph Schoon (63.7k●3●36●48)
| answered May 20 '13, 8:01 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER 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.
Comments
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
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.
Comments
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)