- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2015 08:56 AM
Hello all,
I'm currently working on a script to count the number of tasks assigned to "My Group" based on my groups work. I just need to get a count of the number of tasks and nothing else. I've tried a couple of different things, but this is where the script is currently at:
getTeamTaskCount: function() {
var user_groups = gs.getUser().getMyGroups();
gs.log(user_groups);
var cnt = 0;
var gr = new GlideRecord('task');
gr.addQuery('assignment_group', 'IN', user_groups);
gr.addQuery('active', true);
gr.addQuery('assigned_to', null);
gr.query();
while(gr.next()){
gs.log(cnt + ": " + gr.getDisplayValue());
cnt= cnt + 1;
}
return cnt;
}
This query is updating the count but it is completely off...I think that the query is skipping groups based on the task numbers I've checked.
It would be great if someone could help me out with this issue.
Thanks,
Jake
Solved! Go to Solution.
- Labels:
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2015 09:01 AM
Hello Jacob,
Please try this variation of you script:
getTeamTaskCount: function() {
var user_groups = gs.getUser().getMyGroups();
user_groups = user_groups.toString().replace('[', '').replace(']', '');
gs.log(user_groups);
var cnt = 0;
var gr = new GlideRecord('task');
gr.addQuery('assignment_group', 'IN', user_groups);
gr.addQuery('active', true);
gr.query();
while(gr.next()){
if(! gr.assigned_to){
gs.log(cnt + ": " + gr.getDisplayValue());
cnt++;
}
}
return cnt;
}
Let me know the outcome.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2015 09:01 AM
Hello Jacob,
Please try this variation of you script:
getTeamTaskCount: function() {
var user_groups = gs.getUser().getMyGroups();
user_groups = user_groups.toString().replace('[', '').replace(']', '');
gs.log(user_groups);
var cnt = 0;
var gr = new GlideRecord('task');
gr.addQuery('assignment_group', 'IN', user_groups);
gr.addQuery('active', true);
gr.query();
while(gr.next()){
if(! gr.assigned_to){
gs.log(cnt + ": " + gr.getDisplayValue());
cnt++;
}
}
return cnt;
}
Let me know the outcome.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2015 09:13 AM
Thanks Edwin! That is exactly what I needed. I was having trouble trying to get the toString() to work before, but it returns the correct number now.
Thanks a bunch,
- Jake
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2015 09:15 AM
No problem Jacob! Glad it is working now.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2015 04:37 AM
Hello There,
I started to work on servicenow recently and I am stuck. I really need your help. I have two questions about the topic above.
1. I copy and paste getTeamTaskCount: function() in order to count the number of tasks assigned to "my group" in UI Actions. But I don't know where I have to collect the result. Can you help me please ? (It may not have to be copy and paste in UI Actions and I really don't know where to do).
2. My main TASK : I want to count the number of tasks for each request when the user open the request.
Let me explain : Le'ts say for example when I open the request number REQ001, I want to know that there is 3 tasks (RITM0021, RITM002, RITM003).
For the request REQ002, there is only one task (RITM004), etc (only when i open the request)
This is the script I have written, but It's not working :
var reqItems = new GlideAggregate('sc_req_item');
reqItems.addQuery('current.sys_id');
reqItems.addAggregate('COUNT');
reqItems.query();
if (reqItems.next()) {
alert('task count: ' + reqItems.rows.length);
}
Thank you so much for your help