How to set the number of records in the Report in the dashboard

SanikaK
Tera Contributor

I have requirement where I have created the Dashboard. In that dashboard I have added the report through widget. The Report shows the list of total numberof records in the table. I need to show only the 1st 10 records in that report. How should I configure this. 

Attaching the current dashboard for reference.

13 REPLIES 13

SanikaK
Tera Contributor

Hi @Chaitanya ILCR ,

I can see some changes when I made the sandbox enabled to true. Earlier in Sysid it was showing as null, but now it is giving some value but still the list is not visible

Attaching the updated screenshots

Hi @SanikaK ,

it should work

did you set the correct table in the report? (is it sn_cim_register?)

 

ChaitanyaILCR_0-1747721789432.png

update the script include's caller access and accessible from and sandbox enabled

and the filter to include scopename(sn_cim.RecordFetcher2) 

javascript:new sn_cim.RecordFetcher2().getTop10SysIds()

 

if you are not able update it

 

create a new script include 

name:RecordFetcher2 

snadbox enabled: true

accessible from : all application scopes

caller access:caller tracking

var RecordFetcher2 = Class.create();
RecordFetcher2.prototype = {
    initialize: function() {},

    getTop10SysIds: function() {
        var result = [];

        var gr = new GlideRecord('sn_cim_register'); //update your table name looking at screenshot looks like those are continual improvement records

        // gr.addEncodedQuery('addYOurEncodeQuery here'); //add encoded query here
        gr.setLimit(10);
        // gr.orderByDesc('sys_created_on') use orderBy if need  I'm commenting this
        gr.query();

        while (gr.next()) {
            result.push(gr.getValue('sys_id'));
        }

        return result.join();
    },

    type: 'RecordFetcher2'
};

 

ChaitanyaILCR_1-1747722091843.png

 

 

filter sys id IS ONE OF javascript:new sn_cim.RecordFetcher2().getTop10SysIds() in case of old one remove 2 from RecordFetcher2

 

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

SanikaK
Tera Contributor

Hi @Ankur Bawiskar 

Yes in the report I want to list only the latest 10 reocrds. Currently, in the table total number of records in 46.

@SanikaK 

please create classless script include like this and see

Then call in report filter condition like this

SysId [IS ONE OF] javascript: latestRecords();

function latestRecords() {
    try {
        var arr = [];
        // your GlideRecord and iterate and then push sysId in array
        var gr = new GlideRecord("tableName");
        gr.orderByDesc("sys_created_on");
        gr.addQuery("name", "value");
        gr.query();
        while (gr.next()) {
            arr.push(gr.getUniqueValue());
        }
        return arr.toString();

    } catch (ex) {
        gs.info(ex);
    }
}

AnkurBawiskar_0-1747648140172.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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