Scripted report - To show a calculated value from the backend (script include)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 06:55 AM - edited 03-12-2024 07:01 AM
Hello all,
I have a requirement to perform the below mathematical calculation in the script include and push that calculated value into a standard report.
I have seen standard report that displays records based on script include function that returns an array of sys id's.
I am not sure about how to write this below background script (that do the mathematical calculation) in script include the function and how to call the output value in the standard report. Any help would be appreciated.
Thanks,
Keerthana
var ga = new GlideAggregate('ssa_deflection_metric');
ga.addEncodedQuery("type=30^deflection_pattern.deflection_configuration.activity_context=7b43fb645383201033cdddeeff7b1246");
ga.query();
while (ga.next()) {
var totalpotential = ga.getRowCount();
}
var gr = new GlideAggregate('ssa_deflection_metric');
gr.addEncodedQuery("type=20^deflection_pattern.deflection_configuration.activity_context=7b43fb645383201033cdddeeff7b1246");
gr.query();
while (gr.next()){
var confirmeddeflection = gr.getRowCount();
}
var gp = new GlideAggregate('ssa_deflection_metric');
gp.addEncodedQuery("type=10^deflection_pattern.deflection_configuration.activity_context=7b43fb645383201033cdddeeff7b1246");
gp.query();
while (gp.next()){
var Nodeflection = gp.getRowCount();
}
gs.print('Total Potential deflection = '+ga.getRowCount());
gs.print('confirmed deflection = '+gr.getRowCount());
gs.print('No deflection = '+gp.getRowCount());
gs.print('Potential deflection = ' + (ga.getRowCount()-(gr.getRowCount()+gp.getRowCount())));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2024 07:26 AM - edited 03-13-2024 07:28 AM
Hi @Raja keerthana ,
What is it that you would like to obtain by your script? Currently you're just quiring 3 times and put the row count into variables? Secondly, you can't just put a number from a script include into a report - you need to provide the sysid or similar to fetch the records when running the report.
If you would like to do a calculation like in above script, you should utilize performance analytics instead of the report designer.
For calling script includes from reports, please see this ServiceNow documentation: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0832058
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
best regards
Anders
If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.
Best regards
Anders
Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2024 02:31 AM
Thank you so much for your reply..!
Yes, I know and understand, I need to get sys_id's in th e script to call it in the report. I know we can achieve this calculation through Performance analytics formula indicator too.
The problem is that I want this report/PA widget to work with a filter based on the created date of deflection metric in the ashboard. As you know, we cannot make the interactive filter work with PA widget, I wanted to know if we can achieve this through a scripted report.
Thanks,
Keerthana