It's all about the answers!

Ask a question

How to get a calculated values script to work


Jeffrey Burke (312637) | asked Oct 29 '13, 11:39 a.m.

New to RTC and I'm trying to get a calculated values script to work. I've tried using the sample in this article: https://jazz.net/library/article/1003/

Nothing happens when I create a work item or edit and then save the work item. I was expecting the script to run and to update the custom attribute that uses the Calculated Value script. The attribute does have dependencies selected.

Questions:

1. If the script throws errors where can I find the error log?

2. Any tips on where to look for why it's not working?

Version of RTC is 4.0.3

Thanks!

2 answers



permanent link
Piotr Aniola (3.7k11738) | answered Oct 29 '13, 11:46 a.m.
Hello,

the most often overlooked factor is that you need to enable the scripts. Search for the Enable Process Attachment Scripts and make sure it is set to true. Search for it in Advanced Properties. This is described in the document you mentioned, so just to double check.

Once you save the workitem, you can check ccm.log to see if the script generated any error.

Comments
Millard Ellingsworth commented Oct 29 '13, 12:06 p.m.
FORUM ADMINISTRATOR / JAZZ DEVELOPER

There is a brief discussion here on debugging via the web UI (and much more discussion about attribute customization in general -- note the section about the JavaScript API as not all attribute types are easily handled in scripting). Once you set the debug flag you can use the developer tools in the browser to set breakpoints in the script and investigate what's happening. You can also use console.log() if you'd prefer and look for that output in the browser console.


Jeffrey Burke commented Oct 29 '13, 12:10 p.m.

Thanks for the replies!

The Current Value was set to True.

Where can I find the ccm.log?

Thanks!


Piotr Aniola commented Oct 29 '13, 12:18 p.m.

Assuming you're using Tomcat, it is located in
<JazzServer>/server/logs

In case of WAS:
<WebSphere install dir>/AppServer/profiles/<profile name>/logs



Jeffrey Burke commented Oct 29 '13, 12:47 p.m.

Thanks again. Found the WebSphere directory (has lots of files) but don't see a ccm.log file.


Piotr Aniola commented Oct 29 '13, 12:52 p.m.

Depending on how your CCM application is named, the log file can be named differently. 'ccm' is the default name, but can also be jazz.log, or something else.


Millard Ellingsworth commented Oct 29 '13, 12:54 p.m.
FORUM ADMINISTRATOR / JAZZ DEVELOPER

Did you search for ccm.log and not find one anywhere in that folder?


Personally, I've always use the debug URL and the browser debugger to work on scripts. It's typically quite simple:
  1. Add ?debug=true to the right part of the URL (before the #)
  2. Open browser developer tools
  3. Reload page if needed
  4. Open Source Panel and look for your named script
  5. Set a breakpoint on one of the early lines of your script 
  6. Step through it using the inspector to see what is happening
  7. (often notice stupid JavaScript syntax error that was the problem all along)
If someone hasn't made a short video/tutorial for this already, perhaps I will. If I can find one I'll add here.


Jeffrey Burke commented Oct 29 '13, 1:04 p.m.

Thanks again. I'm checking ever file (that has been recently modified) in the logs folder. Haven't found it yet but I'm still looking.


Jeffrey Burke commented Oct 29 '13, 1:06 p.m.

Millard 

 Yes.


Jeffrey Burke commented Oct 29 '13, 1:23 p.m.

Trying to debug. Using Firefox. Its lists tons of javascript files except for the one I want it to list.


Millard Ellingsworth commented Oct 29 '13, 1:41 p.m.
FORUM ADMINISTRATOR / JAZZ DEVELOPER

Did you enable process scripting (if needed) as Piotr mentioned? Yes, it's a long list, but your file should be there using the name you gave it. In Chrome, my scripts are often at the end of the long list of files. If you type the first few characters of your script name, won't FF filter the list for you? Anyway, if process customization scripts are enabled, your file should be there somewhere. 


Jeffrey Burke commented Oct 29 '13, 1:42 p.m.

Using IE and I'm able to debug now. Finding some errors. Thank you both for your help. Just need to fix some errors.


Jeffrey Burke commented Oct 29 '13, 1:55 p.m.

Did you enable process scripting (if needed) as Piotr mentioned? Yes it was already enabled.


Jeffrey Burke commented Oct 29 '13, 3:22 p.m.

Seems like the script (for the calculated value) is never being reached because it is first failing on an error of "Object doesn't support property or method 'getElementByTagName". I removed the calculated value script and ran while debugging and I'm getting the same error.


Millard Ellingsworth commented Oct 29 '13, 3:39 p.m.
FORUM ADMINISTRATOR / JAZZ DEVELOPER

hmm, I'm using 4.0.3 and I don't recall seeing any errors. Are you using an example from the article exactly or using the article as guidance? Unless that error is tanking your whole UI, it's probably just moving on. Maybe time to switch back to FF. ;-) 


Jeffrey Burke commented Oct 29 '13, 3:52 p.m.

I was using the Age Calculation script. I removed it and then started debug while editing a work item and I get the "Object doesn't support property or method..." error when trying to Save. The Save won't complete until I stop debugging. When not in debug mode I can edit and save the work item with no problems.

I guess I'll try FF again.


Jeffrey Burke commented Oct 29 '13, 4:11 p.m.

I think your right it is just moving on. Thus no errors are being hit within the CalculateAge script (added it back in) but the field is not being updated.


Millard Ellingsworth commented Oct 29 '13, 4:24 p.m. | edited Oct 29 '13, 4:27 p.m.
FORUM ADMINISTRATOR / JAZZ DEVELOPER

Is the script being run? Is it returning the correct value? Put a breakpoint on several lines and make sure the code is executing and know what it is returning. If you copied the code exactly, you may want to change it to create the return value, then return it, so you can see the value in the debugger.


Ah, just read through the example more carefully. Because it is dependent on ModificationDate and that won't change on the client, it may not update until saved and that update may not happen until the server side and won't be visible in the client unless it is refreshed. An unfortunate example as you can't debug it on the client or even see it change on the client as you'd expect. I guess the way it is intended to work, you make changes, save, then the Age updates.

You can always cheat -- make it dependent on something else you can change in the UI so you can see it work. If you make it dependent on, say, Description, you should be able to trigger it from the UI.


Jeffrey Burke commented Oct 30 '13, 8:38 a.m.

I'll give that a try. thanks for the suggestion.


Jeffrey Burke commented Oct 30 '13, 9:02 a.m.

A "Unknow type" error is being thrown.


Jeffrey Burke commented Oct 30 '13, 9:40 a.m.

Still can't find the CalculateAge script to be able to put break points in it. Any hints on finding the script while debugging (Using FireFox or IE)?


Ralph Schoon commented Oct 30 '13, 10:20 a.m. | edited Oct 30 '13, 10:21 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Try using Chrome, I find it easier to find the scripts. We described debugging with FireFox a bit in Lab 5 of https://jazz.net/library/article/1093 (At the end), but I sometimes find the scripts immediately and sometimes find myself frantically trying to find them in FireFox.

FYI, some scripts might run on the server and not in the client.

In Chrome Use Tools>Developertools and you can find the scripts in Resources>Frames>(window)>Scrips, I believe.


Jeffrey Burke commented Oct 30 '13, 11:14 a.m.

Ralph - thanks for the suggestion but unfortunately I won't be abble to use google chrome.


Millard Ellingsworth commented Nov 01 '13, 2:15 p.m. | edited Nov 02 '13, 3:10 p.m.
FORUM ADMINISTRATOR / JAZZ DEVELOPER

I've been working an article that lays out the process with a detailed example, including debugging steps, etc. Using a relatively recent version of Firefox (ESR 24.0) I don't see the script. Filtering the list doesn't find it and a massive scroll and stare doesn't either. Works fine in Chrome. Let me try IE. Mostly wanted you to know I haven't given up on this.


Millard Ellingsworth commented Nov 01 '13, 3:06 p.m.
FORUM ADMINISTRATOR / JAZZ DEVELOPER

Wow, nor in IE. This works perfectly in Chrome (sorry you are unable to use it). I'll see if I can figure out what's up, but I can't offer you much help with debugging this in a non-Chrome environment if we can't figure out how to find the script. 


I was able to use console.log("got to here"); and see those in the FF console, but that's not a very productive way to work (and you can't use the debugger to inspect the structure of things that way).


Jeffrey Burke commented Nov 05 '13, 12:48 p.m.

Thank you very much for looking into this!!


Millard Ellingsworth commented Nov 05 '13, 1:44 p.m.
FORUM ADMINISTRATOR / JAZZ DEVELOPER

I'm happy to share a draft of the piece I'm working on in case it will help. Shoot me an email: millarde@us.ibm.com 


Jeffrey Burke commented Nov 06 '13, 11:07 a.m.

Just sent you an email. Thanks again!

showing 5 of 27 show 22 more comments

permanent link
Millard Ellingsworth (2.5k12431) | answered Nov 18 '13, 8:36 p.m.
FORUM ADMINISTRATOR / JAZZ DEVELOPER
I'm hoping this new article will help you figure this out: https://jazz.net/library/article/1360

Comments
Jeffrey Burke commented Dec 03 '13, 4:23 p.m.

Thanks again Millard! I haven't had a chance to work on this task for awhile now. I appreciate all the help you have provided.


Millard Ellingsworth commented Dec 03 '13, 4:38 p.m.
FORUM ADMINISTRATOR / JAZZ DEVELOPER

My pleasure. If you have more questions, just ask them. 


Jeffrey Burke commented Dec 10 '13, 12:39 p.m.

Will do. Thanks!

Your answer


Register or 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.