How to wrap script in a script include a call from a report created through the report designer

AndersBGS
Tera Patron
Tera Patron

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:

AndersBGS_0-1710150167654.png

The database view for dashboard is configured as below:

AndersBGS_1-1710150240078.png

AndersBGS_2-1710150295529.png

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/

11 REPLIES 11

Ankur Bawiskar
Tera Patron
Tera Patron

@AndersBGS 

to call script include from report condition, it should be client callable

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar ,

 

It is, but I still doesn't get any values:

 

AndersBGS_0-1710151340441.png

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/

@AndersBGS 

please share the script section

Also how are you calling it in report filter condition?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar 

 

AndersBGS_0-1710152586974.png

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:

 

AndersBGS_1-1710152663397.png

 

Script from the condition:

javascript&colon;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/