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 09:05 AM
What's your actual BR code look like?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2016 09:23 AM
William,
I would use the business rule something like this:
var sctask = new GlideRecord('sc_task');
sctask.addQuery('request_item', current.sys_id);
sctask.addActiveQuery();
sctask.query();
gs.addInfoMessage('Tasks : ' + sctask.getRowCount());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2016 10:09 AM
Shouldn't the BR look something like:
var sctask = new GlideRecord('sc_task');
sctask.addQuery('request_item', current.sys_id);
sctask.addActiveQuery();
sctask.query();
if (sctask.next()) {
gs.addInfoMessage('Tasks : ' + sctask.getRowCount());
}
Seems you forgot the IF-statement.
I threw the above code in a BR display for sc_req_item table and got this:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2016 12:22 PM
Thank you everyone. Is it possible to perform this with GlideAggregate instead of GlideRecord?