count the number of catalog tasks in a request
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2016 08:35 AM
I have read through all of this post How to count the number of task assigned to a request number ? and the original request was for a count of the number of requested items; I am trying to figure out the proper code for a count of the number of catalog tasks. Can someone help me with this please! I am running out of time on this and my boss is getting antsy.
I have been testing this background scripts and it keeps giving me 31 active tasks - the total # of active tasks, which tells me it's accessing the right table. But when I transfer it to my display BR, based on the post, it's returning "Tasks: 0" every time, why?
var taskItems = new GlideAggregate('sc_task');
taskItems.addQuery('task','c4288fd50a0a0b1200577058fffbf9a3'); //Request sys_id for RITM0000010
taskItems.addAggregate('COUNT');
taskItems.addActiveQuery(); //only counts the active items
taskItems.query();
if (taskItems.next()) {
gs.print('Tasks: ' + taskItems.getAggregate('COUNT'));
}
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2016 02:20 PM
Thanks goranlundqvist, so I am running the GA queries on the right tables then? I am still coming up with 0's on these queries - thanks everyone for the help. I am also sticking to running this on the Catalog Task table, if that makes a difference.
I really wish there is someone I could just talk to - I feel like a simple verbal explanation would clear this up in < 5 minutes. And, is there a table somewhere that I can find all of these "request_item" selectors? I notice they don't match up 1:1 with the table names.
(function executeRule(current, previous /*null when async*/) {
var reqItems = new GlideAggregate('sc_req_item');
reqItems.addQuery('parent',current.sys_id);
reqItems.addActiveQuery();
reqItems.addAggregate('COUNT');
reqItems.query();
if (reqItems.next()) {
gs.addInfoMessage('Requested Items: ' + reqItems.getAggregate('COUNT'));
}
var taskItems = new GlideAggregate('sc_task');
taskItems.addQuery('request_item.parent', current.sys_id);
taskItems.addActiveQuery();
taskItems.addAggregate('COUNT');
taskItems.query();
if (taskItems.next()) {
gs.addInfoMessage('Tasks: ' + taskItems.getAggregate('COUNT'));
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2016 02:45 PM
Yea,
Everything seems to be in order. Kind of hard not knowing what could be wrong when you aint sitting at the instance looking.
What happens and you take the first part of the code, and replace second line with a request sys_id like this which is from my dev instance.
var reqItems = new GlideAggregate('sc_req_item');
reqItems.addQuery('parent','c42441770a0a0b12001a2f5108d0794a');
reqItems.addActiveQuery();
reqItems.addAggregate('COUNT');
reqItems.query();
if (reqItems.next()) {
gs.addInfoMessage('Requested Items: ' + reqItems.getAggregate('COUNT'));
}
Then you take the code and run it in the Script - Background. Do you still get 0?
About finding out about the DOT walking etc. It kind of one of those things that suddenly just falls into place and then you get it..
What I did in the begining was that if I was doing for example sc_req_item. Then I knew I was going for the requested item records.
To know more about sc_req_item I would go first to tables & column and check out the table sc_req_item.
Here you can find out all fields that that table uses.
If it got an icon like Parent have here. I indicates It's a reference field and you can "dot walk" into that table and fetch data.
If you wonder what parent contains you can either go to sc_req_item.list and pull out the column there and see what it is, or put the field out on the form.
Alot of stuff in ServiceNow is experience and I found alot of tables that I didn't knew existed before. I'm throwing it up in a blog post soon just to share and hope other new people don't have to pull their hair like I did.
Just keep asking if you got anything else in your mind. I don't have all the answers, but perhaps I can help you find them and learn something myself as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2016 05:27 AM
Where is your blog located goranlundqvist? I would love to read it when you get that post finished.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2016 05:46 AM
Look at my signature for the blog
Ahhh.. that the thing.
there is the problem. the display BR should point at sc_request. since it should run when you open an request and that is in the sc_request.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2016 05:56 AM
Would you be up for a Google Hangout, or some form of screen sharing goranlundqvist?