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

Hi Goran,



I need similar help for my script.Let me know if you can provide me ur help.


Hi,



I just saw this thread..I have a kind of similar situation. I need to accomplish the following:



The short description of the requested item is based on another business rule on the requested item table. In other words the short description on the requested item is made up a series of inputs on the form then and on submit it creates the output and is display on the requested item on the short description field. then what I was doing is moving that output into the short description of the task yet here is where i am stuck as it works if the request had one task but if they create another task it copies the same short description over instead of leaving the new task with a different input.



This is the BR that I have on the task table to copy the short description to the task from the request_item.




(function executeRule(current, previous /*null when async*/) {



      // Add your code here


     



      current.short_description = current.request_item.u_short_description;



})(current, previous);



I changed it to the following to try to make it only copies it to the first task but it failed:



var gr = new GlideRecord("sc_req_item");


gr.addEncodedQuery("request_item=" + current.request_item);


gr.query();


var count = gr.getRowCount();


if(count == 1)


{


current.short_description = current.request_item.u_short_description;


current.update();


}



Please advise?


Hi,



If the task is generated using workflow activity ,I think it will be a better idea to set the short description   using script in the task activity of the first task activity in workflow.




Thanks,


JJ