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

Can you change the type of the field from String to Number? and remove the parseInt and just do the addition


Works like a treat. Thank you so much Sirkanth.


Is there any way to get the status of each Incident task (closed one also) like a group by on Incident so that Incident task will be listed down?


any approach?


Vikas-Malhotra
Mega Guru

Hi Venkat,



can you tell what is the error that you get ?



-vikas