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

Ankur Bawiskar
Tera Patron
Tera Patron

@Aruna Sree Yela 

the report should be client callable and something like this

function checkRecords(){
	try{
		// your code here

		return array;
	}
	catch(ex){
		gs.info(ex);
	}
}

AnkurBawiskar_0-1689685318908.png

How to call it in report condition?

1) create report on incident table

2) add the filter condition as this

sys_id [IS ONE OF] javascript: checkRecords()

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

Hi @Ankur Bawiskar ,

 

Thanks for your time.

 

I tried your suggestion, even though I'm getting only one location's incidents.

 

Script Include:

 

ArunaSreeYela_0-1689686225551.png

 

Report:

 

ArunaSreeYela_1-1689686332362.png

 

Kindly correct me if I misplaced the return value.

 

Thanks

Aruna

@Aruna Sree Yela 

try this once

function checkRecords(){
	try{
		var arr = [];
		var locationRec = new GlideRecord('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);
	}
}

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

@Ankur Bawiskar 

 

The condition is not fetching the sys_id's, instead showing the callback function(highlighted in 2nd snip). Tried to change 12th line with getValue('sys_id') but no luck.

 

ArunaSreeYela_0-1689689667049.pngArunaSreeYela_1-1689689716228.png