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

Hi @Ankur Bawiskar ,

 

Thank you for the solution. I have a small query regarding this.

 

While I'm running the report it's taking too long to load that report, I feel that's due to fetching the sys_id's. Is there any possibility to avoid this situation.

 

Thanks

Aruna 

@Aruna Sree Yela 

it will take time and will have performance impact since it's querying all locations and entire incident table

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

@Ankur Bawiskar ,

 

Here, I'm scheduling the report, this performance impact won't effect that right?