Is there any way to run script include in report?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2022 05:48 AM
I have written a script include
function P2_Count() {
gs.log("Inside Script include");
var str = [];
count = new GlideAggregate('incident');
count.addEncodedQuery('assignment_group=6351d485db4e67803629f7051d9619e9^priority=2^active=true'); #for particular group's incident
count.addAggregate('COUNT', 'cmdb_ci');
count.groupBy('cmdb_ci');
//count.orderByAggregate('COUNT', 'cmdb_ci');
count.addHaving('COUNT', '>', 5);
count.query();
while (count.next()) {
str.push(count.cmdb_ci.toString());
}
gs.log(str);
return str;
}
and , called this script include in report as;
javascript: P2_Count();
I am getting results but not getting any logs as I have entered logs in between the code
And also Properly not working the line
count.addHaving('COUNT', '>', 5);
getting random count in report
Please Find the Attachments and Please help me out...
Can we call script include from any report?
- Labels:
-
Dashboard
-
Multiple Versions
-
Reporting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2022 06:00 AM
Hi Yash,
The way you called script include is not correct one.
You should be using below format to call script include,
javascript : new scriptIncludeName().P2_Count();
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Community Rising Star 2022
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2022 08:09 AM
Hello Abhijit ,
Thanks for your reply...
I tried that way of calling script include and gs.info instead of gs.log even then I am not getting logs
var Yash_test = Class.create();
Yash_test.prototype = Object.extendsObject(AbstractAjaxProcessor, {
P2_Count: function() {
gs.info("Inside Script Yash test includeeeeeee");
var str = [];
count = new GlideAggregate('incident');
count.addEncodedQuery('assignment_group=6351d485db4e67803629f7051d9619e9^priority=2^active=true');
count.addAggregate('COUNT', 'cmdb_ci');
count.groupBy('cmdb_ci');
//count.orderByAggregate('COUNT', 'cmdb_ci');
count.addHaving('COUNT', '>', 7);
count.query();
while (count.next()) {
str.push(count.cmdb_ci.toString());
}
gs.info(str);
return str;
},
type: 'Yash_test'
});
javascript:new Yash_test().P2_Count();
you can see here below even I entered COUNT > 7 I am getting results of count 2 also
you can see here in below pic no logs are there
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2022 06:05 AM
In your Client callable script include following syntax is missing
var testdata = Class.create();
testdata.prototype = Object.extendsObject(AbstractAjaxProcessor, {
when we call script include in report then sys_id is javascript:new ReportUtils().getRecords() where "ReportUtils" is the script include name and getRecords is the function name in the script include. In your case only function name calls hence script include not call properly.
Try gs.info for log message in script include rather than gs.log
Check all above thinghs and let us know it will hep or not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2022 08:05 AM
Hello Kalyani ,
Thanks for your reply...
I tried that way of calling script include and gs.info instead of gs.log even then I am not getting logs
var Yash_test = Class.create();
Yash_test.prototype = Object.extendsObject(AbstractAjaxProcessor, {
P2_Count: function() {
gs.info("Inside Script Yash test includeeeeeee");
var str = [];
count = new GlideAggregate('incident');
count.addEncodedQuery('assignment_group=6351d485db4e67803629f7051d9619e9^priority=2^active=true');
count.addAggregate('COUNT', 'cmdb_ci');
count.groupBy('cmdb_ci');
//count.orderByAggregate('COUNT', 'cmdb_ci');
count.addHaving('COUNT', '>', 7);
count.query();
while (count.next()) {
str.push(count.cmdb_ci.toString());
}
gs.info(str);
return str;
},
type: 'Yash_test'
});
javascript:new Yash_test().P2_Count();
you can see here below even I entered COUNT > 7 I am getting results of count 2 also
you can see here in below pic no logs are there