How to wrap script in a script include a call from a report created through the report designer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 02:48 AM
Hi all,
I have created below script which reference a database view in a custom scoped app, where dt_dashboard.sysid reference the dashboard sysid. I need to populate this script (or similar) in a script include which I then call from a report created through the report designer. How to do this in the best way?
var dashboards = new GlideRecord('x_431699_dashboard_items');
dashboards.addNotNullQuery('dt_dashboard.name');
dashboards.orderBy('dt_dashboard.name');
dashboards.query();
gs.info('---> ' + dashboards.getRowCount());
var dashboardList = [];
while(dashboards.next()) {
dashboardList.push(dashboards.dt_dashboard.name.trim());
}
var arrayUtil = new ArrayUtil();
dashboardList = arrayUtil.unique(dashboardList);
gs.info('---> ' + dashboardList.length);
for (var i = 0; i < dashboardList.length; i++) {
gs.info('---> ' + dashboardList[i]);
}
The report on the dashboard whiteout any filtration looks like below:
The database view for dashboard is configured as below:
Basic need is, I need to query the unique values from the database view and create a report for this.
@Technomonk @Tai Vu @Ankur Bawiskar @Community Alums
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-11-2024 02:57 AM
to call script include from report condition, it should be client callable
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 03:02 AM
Hi @Ankur Bawiskar ,
It is, but I still doesn't get any values:
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-11-2024 03:07 AM
please share the script section
Also how are you calling it in report filter condition?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 03:25 AM
Complete script from script include:
function getUniqueDashboardNames() {
var dashboards = new GlideRecord('x_431699_dashboard_items');
dashboards.addNotNullQuery('dt_dashboard.sys_id');
dashboards.orderBy('dt_dashboard.sys_id');
dashboards.query();
//& gs.info('---> ' + dashboards.getRowCount());
var dashboardList = [];
while(dashboards.next()) {
dashboardList.push(dashboards.dt_dashboard.sys_id.trim());
}
var arrayUtil = new ArrayUtil();
dashboardList = arrayUtil.unique(dashboardList);
// gs.info('---> ' + dashboardList.length);
// for (var i = 0; i < dashboardList.length; i++) {
// gs.info('---> ' + dashboardList[i]);
return dashboardList;
}
// Call the function to get the unique dashboard names
var uniqueDashboardNames = getUniqueDashboardNames();
Condition from the report:
Script from the condition:
javascript:DashboardItemScriptInclude.getUniqueDashboardNames();
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/