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

after this line, please add this-


grInc.u_ task_count= grInc.u_ task_count + 1;


grInc.setWorkfalse(false); //if you dont want any BR to trigger on the incident table


grInc.update();


the values are getting appended


Count shows


0111111


It is not adding/suming up the values


When i use


grInc.u_ task_count = grInc.u_ task_count++;


it comes with decimal value like 1.0 , 2.0


You can use the javascript parseInt function to force the string to integer and add the value and put it back -


grInc.u_ task_count= parseInt(grInc.u_ task_count) + 1;


grInc.setWorkfalse(false); //if you dont want any BR to trigger on the incident table


grInc.update();


thanks srikanth but it throws error message


Unique Key violation detected by database (Duplicate entry 'u_task_count' for key 'PRIMARY')