calling script include in report

Deepthi13
Tera Expert

 

i tried in following way but when i RUN report 0 records where displaying, when i run same script in background script i am getting desired out put after printing. Please suggest.

please find my screen shot and script as below

 

1 ACCEPTED SOLUTION

Just to reiterate: you only call scriptIncludeName().methodName() if you have defined a class for your script include. Deepthi, you have written a classless script include so you need to call it as you were:

javascript: getDupes()

To confirm, you definitely need to have the client callable box ticked in order to call this in a report condition.

View solution in original post

20 REPLIES 20

Rahul Kumar17
Tera Guru

hi

 

i have checked ur code is correct run in background script

var dupRecords = []; 
 var gaDupCheck1 = new GlideAggregate('cmdb_ci_computer'); 
 gaDupCheck1.addQuery('active','true'); 
 gaDupCheck1.addAggregate('COUNT', 'serial_number'); 
 gaDupCheck1.groupBy('serial_number'); 
 gaDupCheck1.addHaving('COUNT', '>', 1); 
 gaDupCheck1.query(); 
 while (gaDupCheck1.next()) { 
 dupRecords.push(gaDupCheck1.serial_number.toString()); 
 } 
 gs.print(dupRecords);

 

it's giving the value 

56WHL71,AEX5635Z0001AC,L3BB911

only mistake this line

javascript : new script_include_name.method_name();

thanq
If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

hi rahul,

pls check below and suggest if some thing wrong in calling script include

my script include as below,

function getDupes(){
var dupRecords = [];
var gaDupCheck1 = new GlideAggregate('cmdb_ci_computer');
gaDupCheck1.addQuery('active','true');
gaDupCheck1.addAggregate('COUNT', 'serial_number');
gaDupCheck1.groupBy('serial_number');
gaDupCheck1.addHaving('COUNT', '>', 1);
gaDupCheck1.query();
while (gaDupCheck1.next()) {
dupRecords.push(gaDupCheck1.serial_number.toString());
}
return dupRecords;
}

 

i given as below in report

javascript : new getDupes().dupRecords();

You only call the script include name and then the function name liek that if you've defined a class for your script inculde. Have a look at the link below, it explains the difference and how and when to use them.

https://community.servicenow.com/community?id=community_blog&sys_id=88bce625dbd0dbc01dcaf3231f9619be 

yes,

it's working fine

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

hi,

it's working or not tell me

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar