
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2016 10:36 AM
We recently upgraded to Geneva and I have a very odd problem. I'm have a basic workflow that contains a Approval - User activity. Within the activity, I specify the "wait for" dropdown to be condition based on script. Then, within my script I reference a variable called counts (e.g., counts.total, counts.approved, etc). The problem is that I continue to get the below JavaScript exception indicating the "counts" variable is NOT defined. Thank you in advance for anyone that knows the answer. Thanks.
Todd
Todd Activity Approval(ecb4741613e35e000d0879812244b052): Caught exception in InterpretedScript <refname>: org.mozilla.javascript.InterpretedScriptException: Caught exception in InterpretedScript <refname>: org.mozilla.javascript.InterpretedScriptException: Caught exception in InterpretedScript <refname>: org.mozilla.javascript.JavaScriptException: org.mozilla.javascript.WrappedException: WrappedException of "counts" is not defined.
Approval - User Activity in workflow
// Set the variable 'answer' to '', 'approved' or 'rejected' to indicate the approval status for this approval. When called, the following information is available:
//
// counts.total = total number of users that are part of this approval
// counts.approved = # of users that approved so far
// counts.rejected = # of users that rejected so far
// counts.requested = # of users that are pending approval
// counts.not_requested = # of users that are not pending approval
// counts.not_required = # of users that approval is not required
//
// WHY IS "COUNTS" UNDEFINED!!!! IT SHOULD BE AVAILABLE WITHIN THIS ACTIVITY
gs.addInfoMessage("Counts value from script: " + counts.total);
// temporary code for now while testing...
answer = '';
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2016 07:09 PM
Just to document answer, our problem was that someone had changed the out of the box functionality (I think business rule or work flow activity). It's been a while and I don't recall which one. But, tech support reverted to OO box functionality and it started working again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2016 10:46 AM
Hi Todd, the counts variable is not defined anywhere in your script above, so it doesn't know what "counts" means. Is it referenced in a previous script in your workflow? Or is it on your form perhaps?
If it's on your form, just change it variables.counts.total.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2016 10:57 AM
Hi William,
Thank you for response. Based on ServiceNow documentation (and my experience using the Approval - User activity), the script should NOT have to define the "counts" variable is that is automatically made available to the script. See the document refence link below and screen shot. Also, I ported this code over verbatim from my Fuji instance where it worked perfectly. Any other ideas? Thanks.
Todd
Approval and Rollback Activities - ServiceNow Wiki
p.s., also note the out of box comments provided to the activity when you add it. It says these are available. Thanks again.
- // Set the variable 'answer' to '', 'approved' or 'rejected' to indicate the approval status for this approval. When called, the following information is available:
- //
- // counts.total = total number of users that are part of this approval
- // counts.approved = # of users that approved so far
- // counts.rejected = # of users that rejected so far
- // counts.requested = # of users that are pending approval
- // counts.not_requested = # of users that are not pending approval
- // counts.not_required = # of users that approval is not required
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2016 11:15 AM
Hi Todd, I know this is sort of a non-answer - I'm still trying to figure out your error - but would it be possibly easier to not include the script?
Here's an awesome blog post that provides more info on workflows and approvals in the meantime: Seeking Approval - Part 2: Task vs non-Task approvals and the Approval - Group Activity

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2016 11:22 AM
Hi William,
Thanks again for your time here. Yes, getting rid of the script would surely be easier. The problem is that it doesn't fit our requirements. I actually have a fairly complicated JavaScript that does some look ups based on assignment groups (how many people are in there, etc) and does a calculation to figure out how many need to approve before it's considered approved. Therefore, my approval calculation changes all the time based on the group it's coming from. I'll read up on your link a bit more too.
I think I had a similar problem a while back and if I remember correctly, SN tech support had to apply a patch or something that wasn't on our instance. I may have to go down that route too. Thanks.
Todd