We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Display when there is no data to display in the widget

fujiwara2
Giga Contributor

Hello

If there is no data to display in the widget, I would like to display a phrase such as "There is currently no data to display".
Is this possible?
If possible, please tell me how to change it.

7 REPLIES 7

Thank you very much.

It does not work properly.
The widget displayed something like an empty box.

find_real_file.png

Hitoshi Ozawa
Giga Sage

Hi Fujiwara-san,

Like below.

data.notes = [];
var nowtime = new GlideDateTime();
var company = gs.getUser().getCompanyID();
var annGR = new GlideRecord('announcement');
annGR.addQuery('u_announce_type', 'operationalstatus');
annGR.addQuery('active', true);
annGR.addQuery('u_system_name', company).addOrCondition('u_system_name', 'null');
annGR.addQuery('from', '<', nowtime);
annGR.addQuery('to', '>', nowtime).addOrCondition('to', 'null');
annGR.orderByDesc('sys_created_on');
annGR.query();
if (annGR.hasNext()) {
    while (annGR.next()) {
        var annObj = {};
        //use service portal helper method to get some display values
        $sp.getRecordDisplayValues(annObj, annGR, 'number,title,sys_id');
        //get the first 20 characters of the description
        annObj.note = annGR.getValue('summary');
        //push the populated obj into the array
        data.notes.push(annObj);
    }
} else {
    data.notes.push('There is currently no data to display');
}

Thank you very much.

It does not work properly.
It looks like you're seeing an empty array.
Need to fix HTML Templete?

find_real_file.png