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
10-24-2016 08:05 PM
Hi Goran,
I need similar help for my script.Let me know if you can provide me ur help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2017 07:03 PM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2017 11:55 AM
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