How to count the number of task assigned to a request number ?

zica
Giga Guru

Hello There,

I started to work on servicenow recently and I am stuck. I really need your help. I have one question about the topic above.

-> I want to count the number of tasks for each request when the user click in the request row to open the request.

Let me explain : Le'ts say for example that the request number REQ001 has got 3 tasks (RITM0021, RITM002, RITM003). When the user click on REQ001, I want to collect that there is 3 tasks assigned to this request number.

This is the script I have written into UI ACTIONS, but It's not working :

var reqItems = new GlideAggregate('sc_req_item');

reqItems.addQuery('current.number');

reqItems.addAggregate('COUNT');

reqItems.query();

if (reqItems.next()) {

        alert('task count: ' + reqItems.rows.length);

}

Thank you so much for your help

1 ACCEPTED SOLUTION

Vimal Priya
Giga Guru

Zic,


Its working fine in my instance.


Try doing in your instance.


Mark the answers helpful and correct .


View solution in original post

30 REPLIES 30

gee
Tera Guru

Please have a look at the following link:


Count and Sum and Avg and Min and Max, Oh My!


Sorry there are few mistakes in above code.


Please use this one-



var reqItems = new GlideAggregate('sc_req_item');


reqItems.addQuery('request',current.sys_id);


reqItems.addAggregate('COUNT');


reqItems.query();


if (reqItems.next()) {


  gs.addInfoMessage('task count: ' + reqItems.getAggregate('COUNT'));


}



This will work.



Thanks,


Tanaji


RITM0021, RITM002, RITM003 - These are not called tasks. These are requested items in the request REQ001.


Tasks are generated in the RITMs to fulfill them and tasks start TASK.


Thank you very much for your prompt response and also for your explanation.


The script above works fine and returns me the number of task of one RITMS.


Now you have explained me, I want the number of requested items (sorry not task as i mentionned before) when you open the request.


example : when you open the REQ001, it should tell me "Ritm count : 2"



Can you help me please ? Thank you very much again