Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How many incident tasks are closed for incident

String
Kilo Sage

Hi Team ,

How to check ,how many incident tasks are closed for respective incident using script 

 

Please guide me with best practice 

1 ACCEPTED SOLUTION

nitinsharma2510
Giga Guru

Hey @String ,

You can use the following script for finding the number of closed Incident Tasks for an Incident.

//incident_task is the table name for Incident Task table
var target = new GlideRecord('incident_task');
//replace with incident=sys_id of your incident
//states 3,4,7 correspond to closed complete, closed incomplete & closed skipped respectively
target.addEncodedQuery("stateIN3,4,7^incident=077b6755dbd26c10a6a84de239961911");
target.query();
//getRowCount() returns the number of records returned by the query
gs.info("Number of open Incident Tasks are = " + target.getRowCount());

I would suggest substituting the fields with your data and running it in the 'Scripts - Background' module.

View solution in original post

5 REPLIES 5

nitinsharma2510
Giga Guru

Hey @String ,

You can use the following script for finding the number of closed Incident Tasks for an Incident.

//incident_task is the table name for Incident Task table
var target = new GlideRecord('incident_task');
//replace with incident=sys_id of your incident
//states 3,4,7 correspond to closed complete, closed incomplete & closed skipped respectively
target.addEncodedQuery("stateIN3,4,7^incident=077b6755dbd26c10a6a84de239961911");
target.query();
//getRowCount() returns the number of records returned by the query
gs.info("Number of open Incident Tasks are = " + target.getRowCount());

I would suggest substituting the fields with your data and running it in the 'Scripts - Background' module.