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.

Calling Script Include through Reports

Aruna Sree Yela
Tera Guru

Hi,

 

I have a requirement to provide a report with incidents details where a location contains more than 3 incidents.

 

The Below snip is from incident table grouped by locations, hence I wanna give a report that contains only the incidents from highlighted locations( location contains >= 3 Incidents)

 

ArunaSreeYela_2-1689683770457.png

 

For test, I tried that from Fix Script I'm getting the output as expected. But when I call the same code from script include I'm getting only the incidents from first location. Here I'm providing the details of it.

 

FIX SCRIPT:

 

ArunaSreeYela_1-1689683557924.png

 

OUTPUT:

 

ArunaSreeYela_3-1689683847303.png

 


SCRIPT INCLUDE:

 

ArunaSreeYela_4-1689684039175.png

 

CALLING THE SCRIPT INCLUDE IN FIX SCRIPT:

 

ArunaSreeYela_6-1689684573444.png

 

OUTPUT:

 

ArunaSreeYela_7-1689684615982.png

 

 

Can anyone please help me to fix this issue.

 

Thank you

1 ACCEPTED SOLUTION

@Aruna Sree Yela 

got it

so update as this

function Stores_SI_AB(){
	try{
		var arr = [];
		var locationRec = new GlideRecord('cmn_location');
		locationRec.query();
		while (locationRec.next()) {
			var inc = new GlideRecord('incident');
			inc.addEncodedQuery('location.sys_id=' + locationRec.sys_id);
			inc.query();
			var count = inc.getRowCount();
			if (count > 3) {
				while(inc.next()){
					arr.push(inc.getUniqueValue());
				}
			}
		}
		return arr.toString();
	}
	catch(ex){
		gs.info(ex);
	}
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

12 REPLIES 12

@Aruna Sree Yela 

can you share your earlier script here? don't add screenshot

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

 

function Stores_SI_AB(){
	try{
		var arr = [];
		var locationRec = new GlideRecord('cmn_location');
		locationRec.query();
		while (locationRec.next()) {
			var inc = new GlideAggregate('incident');
			inc.addEncodedQuery('location.sys_id=' + locationRec.sys_id);
			inc.query();
			var count = inc.getRowCount();
			if (count > 3) {
				arr.push(inc.getUniqueValue());
			}
		}
		return arr;
	}
	catch(ex){
		gs.info(ex);
	}
}

@Aruna Sree Yela 

it makes sense showing the locations in report which have more than 3 incidents linked to it

why to have report on incident table?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar ,

 

The condition is on location table, but I want to provide the incident details.

 

Example:

There are 3 locations

let's say

loc1, 4 incidents are from loc1

loc2, 2 incidents are from loc2

loc3, 6 incidents are from loc3

 

So, I want to query if the location contains 3+ incidents or not, if yes those incidents has to be shown.

From the example, it has to show only incidents from loc1 and loc3(4+6 = 10 incidents)

 

@Aruna Sree Yela 

got it

so update as this

function Stores_SI_AB(){
	try{
		var arr = [];
		var locationRec = new GlideRecord('cmn_location');
		locationRec.query();
		while (locationRec.next()) {
			var inc = new GlideRecord('incident');
			inc.addEncodedQuery('location.sys_id=' + locationRec.sys_id);
			inc.query();
			var count = inc.getRowCount();
			if (count > 3) {
				while(inc.next()){
					arr.push(inc.getUniqueValue());
				}
			}
		}
		return arr.toString();
	}
	catch(ex){
		gs.info(ex);
	}
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader