Incident task count query

venkatkk
Tera Contributor

We have Incident and Incident task associated for the Incident. We like to know how many (count) incidents and status of the task task assigned to parent Incident into a separate field called "Task Status & Count" in Incident form.

Incident Table                 :-       Incident

Incident task Table   :-   u_incident_task

New field :-                                       u_task_count_status

I tried with the below query BR on display but it is not working

Table : Incident

var inctask = new GlideRecord('u_incident_task');

  inctask.addQuery('parent', current.sys_id);

  inctask.addActiveQuery();

  inctask.query();

  if (inctask.next()) {

  gs.addInfoMessage('Tasks :   ' + inctask.getRowCount());

  current.u_task_count_status = (sctask.getRowCount() + '-' + inctask.status);

  }

  }

Please help

1 ACCEPTED SOLUTION

If thats your requirement, then you have to write an After BR on Incident task.


You are updating a field in Incident table on the basis of the incident task.


So when any new incident task gets created - query the Parent field of Incident task and get the corresponding Incident sys_id


And make the update on the Incident table's field task count status field



BR on incident task table


Insert and Update


Condition = current.active.changes()


Script -


var grInc = new GlideRecord('incident');


if(grInc.get(current.parent)){


    if(current.active){


        //default task count status to zero


        //if any new incident task is created, then count increase


          grInc.u_task_count_status = grInc.u_task_count_status + 1;


  }


    else{


          //if the incident task is closed, then count decrease active tasks


          grInc.u_task_count_status = grInc.u_task_count_status - 1;


    }


}



Hopefully this helps


View solution in original post

17 REPLIES 17

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Venkat,



sctask.getRowCount()   should be inctask.getRowCount() +


ghsrikanth
Tera Guru

This code will get all the active incident tasks associated to the incident -


var inctask = new GlideRecord('u_incident_task');


  inctask.addQuery('parent', current.sys_id);


  inctask.addActiveQuery();


  inctask.query();



inctask variable will have records of incident task


When you write inctask.next() - it just means you are accessing the first record in the result


and you are storing that incident task status in the incident taskcount status field


Is that what you wanted to do?



And you have mentioned it is a display BR, the display BR is used to store value of server side field in sctrachpad variable



Could you please let us know in example what you want to see in Task Count Status field?


Thanks Srikanth,



i need something like below in Task Count field


if incident INC0001111 has 2 Incident task then in my task count field it should have "Incident Task count is 2 - INCTASK1 is Open - INCTASK2 is Closed"   like this .


is it possible?


venkatkk
Tera Contributor

Hi Teju,


This is not my requirement i need to have Task count number only the count in task count status field (status of the Incident task should be Open)