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.

Insert 10 incidents from Incident table in an array

vinuth v
Tera Expert

Hi All,

 

How to Insert 10 incidents from Incident table in an array.

 

Thanks in advance,

Vinuth

6 REPLIES 6

Himanshu Verma
Tera Contributor

var arr=[];

var gr=new GlideRecord("incident");

gr.addActiveQuery();

gr.setLimit(10);

gr.query();

while(gr.next()){

arr.push(gr.getDisplayValue("number"));

}

gs.print(arr);

debendudas
Mega Sage
Mega Sage

Hi @vinuth v ,

If you want an array of incident which contains specific field values of the record such as Number, Short Description, Caller then you can you the below script:

var incGR = new GlideRecord("incident");
incGR.addEncodedQuery("<ADD YOUR ENCODED QUERY>"); // Add your query as per requirement
incGR.setLimit(10);
incGR.query();

var incidentArr = []; // Incident Array

while(incGR.next()){

	// Preparing the Array of Object based on Incident field values
	incidentArr.push({
		number: incGR.getValue("number"),
		short_description: incGR.getValue("short_description"),
		caller: incGR.getDisplayValue("caller_id")
	});
}

gs.log(JSON.stringify(incidentArr));

If this solution helps you then, mark it as accepted solution ‌‌✔️ and give thumbs up 👍