- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2015 04:56 AM
Hello There,
I started to work on servicenow recently and I am stuck. I really need your help. I have one question about the topic above.
-> I want to count the number of tasks for each request when the user click in the request row to open the request.
Let me explain : Le'ts say for example that the request number REQ001 has got 3 tasks (RITM0021, RITM002, RITM003). When the user click on REQ001, I want to collect that there is 3 tasks assigned to this request number.
This is the script I have written into UI ACTIONS, but It's not working :
var reqItems = new GlideAggregate('sc_req_item');
reqItems.addQuery('current.number');
reqItems.addAggregate('COUNT');
reqItems.query();
if (reqItems.next()) {
alert('task count: ' + reqItems.rows.length);
}
Thank you so much for your help
Solved! Go to Solution.
- Labels:
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2015 05:02 AM
Zic,
Its working fine in my instance.
Try doing in your instance.
Mark the answers helpful and correct .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2015 08:02 AM
Answer = true means that it will send it.
Use an Advanced condition to send a notification based on the current email record, changing field values, or system properties. To send the notification, your advanced condition script must set a global answer variable to true.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2015 10:51 AM
As Berny told, it will send if the aswer is set to true and it will not when answer is set to false.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2015 07:57 AM
Hello,
Thank you for your reply and Help,I have tested your script, but I dont understant it is not working...
Case number 1 : When the request contains only one RITMS, and IF the RITMs is rejected, the RITM state will change to 'close completed'. At this state, the "rejection Email" will be sent (PICTURE NUMBER 1). And then, the system will change the request State to ' Close completed'. There is also a "survey email" already setted up, but I dont want to send it. I only want to send the last Email (survey Email) in the case Number 2, Which is :
Case number 2 : If the request has more than 1 RITM (no matter if some of them have been rejected and/or approved). in other words, in this case, both rejection and survey email will be sent.
you will find my screenshots above : I ONLY TRIED to send the SURVEY email if there is MORE THAN 1 RITMS into the Request (PICTURE NUMBER 2). The script is executed into 'ADVANCED CONDITION' of 'SURVEY email' (PICTURE NUMBER 3).
But it is NOT working.
PICTURE NUMBER 1 : Requested ITEM LEVEL :
PICTURE NUMBER 2 : REQUEST LEVEL, HAS GOT 2 RITMS :
PICTURE NUMBER 3 : ADVANCED CONDITION OF SURVEY EMAIL
If you have any advice for me, I am more than interested,
Thank you very much for your help,
Kind Regards,
ZiA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2015 09:44 AM
Hi ZiA,
Remove the first function line and the last line with the curly bracket and give it a try.
Thanks,
Berny

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2015 10:43 PM
Hi AKb,
First thing you are doing wrong is you are re-declaring the answer variable with set to false. This will always make the advanced condition false. As soon as you set the answer variable it returns from there making the advanced condition false/true depending on your value assignment.
Its a global variable declared by ServiceNow. You don't need to declare it again. Please see the code I have shown in the screenshot below.
If you are declaring a declaring count variable to store the no of RITMs then why are you not using it in the if condition of "reqItems.getAggregate('COUNT')". Please use count variable here.
Why are you writing the code inside a function? And if you are writing it in a function then call the function above its definition. From nowhere you are calling your function.
So remove the code from function and write it directly.
Please use the same code as I have shown above with two changes, one at line 1 and other at line 11.
Change line 1 to "var count = 0;".
Change line 11 to "if(count == 1){"
Please write the code as it is with the above changes and try.
Thanks,
Tanaji