The CreatorCon Call for Content is officially open! Get started here.

count the number of catalog tasks in a request

will_smith
Mega Guru

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'));

  }

42 REPLIES 42

Sorry, not at the moment, sitting at home with alot of kids and kids friends running around.



But after reading the post above, I know the problem.



Its just like you say, its the "current.sys_id" that is messing with you.



When your BR is on sc_request current.sys_id is the sys_id of the request that you are looking at.



when you change your BR to sc_task and click on a catalog task the "current.sys_id" is the sys_id of that task and therfor it doesnt work.



Give a couple of minutes to think and I think we can sort this out.


Add me on linked in and you'll see an update there whenever I put up a new blog   post


will_smith
Mega Guru

Ok, so when I replace the current.sys_id with a Request sys_id I get what I would expect...


Background message, type:info, message: Requested Items: 1


Background message, type:info, message: Tasks: 2



I am running this from a ServiceNow demo instance, if that helps. I will keep poking away at it, the weird thing I keep coming back to is that this works when the BR is pointing to the Catalog Request [sc_request] table, but not the Catalog Task [sc_task]. It's like it doesn't know how to go up the chain...


will_smith
Mega Guru

So I tried the same thing in our Development instance thinking maybe my Demo instance is messed up, but I got the same result - 0's.


will_smith
Mega Guru

Sorry, forgot to include the image of my current BR...



find_real_file.png