The CreatorCon Call for Content is officially open! Get started here.

search result returns blank cards in service portal

rachana_patel
ServiceNow Employee
ServiceNow Employee

Hi , searching for a term in service portal does return results but also returns blank card when view is set to card view.

when we change the view to list view/grid view , there are lines coming in between the populated articles which represent as some article . 

WHy do you think that happens?

 please find screenshot 

1 ACCEPTED SOLUTION

Jonathan Ting
Tera Guru

Hi Rachana,

 

Do you have attachments index on any of your AI search index sources?  If so, it's trying to display those results and doesn't have the correct widget to display the card content. 

 

To fix this you'll need to clone the "Topic Content" widget and add the Attachment table to contentTabletoWidget

JonathanTing_0-1689803180037.png

Then you'll need to create a new widget to display the content, I just cloned the kb-content widget.

Here's the server script I cleaned up 

(function () {

    var attSysId = options.content;
    var attTable = options.content_table;
    var isFeatured = options.isFeatured || false;
    var viewType = options.listType || 'card';
    var title = options.widgetTitle;
    var widgetSysId = options.widgetSysId;
    var searchModeEnabled = options.searchModeEnabled || false;
    var topicId = options.topicForBreadcrumb;

    data.attCardData = {};
    data.attCardData.iconClass = "fa fa-file-text-o";
    data.attCardData.type = gs.getMessage("Attachment");
    data.attCardData.isFeatured = isFeatured;
    data.attCardData.viewType = viewType;
    data.attCardData.widgetTitle = title;
    data.attCardData.widgetSysId = widgetSysId;
    data.attCardData.sysId = attSysId;
    data.attCardData.table = "sys_attachment";

    if (searchModeEnabled) {
        data.attCardData.title = options.title;
        data.attCardData.description = options.text;
        data.attCardData.image = options.image ? options.image + '?t=small' : '';
        data.attCardData.url = '?id=kb_article&sysparm_article=' + options.number;
        if(topicId){
            data.attCardData.url += '&topic_id='+topicId;
        }
        data.attCardData.additionalInfo = options.sys_updated_on;
        data.widgetData = $sp.getWidget("content-card", data.attCardData);
    }
    else {
        if (!attSysId || !attTable)
        return;

        var gr = new GlideRecordSecure(attTable);
        if (gr.get(attSysId)) {
            data.attCardData.title = gr.getDisplayValue('file_name');
            var description = gr.getDisplayValue('text');
            data.attCardData.description = !description ? '' : $sp.stripHTML(description);
            data.attCardData.image = gr.getDisplayValue('image') ? gr.getDisplayValue('image') + '?t=small' : '';
            data.attCardData.url = '?id=kb_article&sysparm_article=' + gr.getValue('number');
            if(topicId){
                data.attCardData.url += '&topic_id='+topicId;
            }
            data.attCardData.additionalInfo = gr.getDisplayValue('sys_updated_on');
            data.widgetData = $sp.getWidget("content-card", data.attCardData);
        } else
            return;
    }
})();

 

Then change the portal page to display the customised widget.

 

The OOB widget is only setup for Catalog items and KB articles, so if it's not the attachments that is causing the issue. I would do a $scope.data dump on the Topic Content widget and check the console to see what is missing, you'll find the table under aisSearchResults

JonathanTing_1-1689803564413.png

 

View solution in original post

3 REPLIES 3

jaheerhattiwale
Mega Sage

@rachana_patel I think you dont have access to see those items. Check the user criteria on those items.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Jonathan Ting
Tera Guru

Hi Rachana,

 

Do you have attachments index on any of your AI search index sources?  If so, it's trying to display those results and doesn't have the correct widget to display the card content. 

 

To fix this you'll need to clone the "Topic Content" widget and add the Attachment table to contentTabletoWidget

JonathanTing_0-1689803180037.png

Then you'll need to create a new widget to display the content, I just cloned the kb-content widget.

Here's the server script I cleaned up 

(function () {

    var attSysId = options.content;
    var attTable = options.content_table;
    var isFeatured = options.isFeatured || false;
    var viewType = options.listType || 'card';
    var title = options.widgetTitle;
    var widgetSysId = options.widgetSysId;
    var searchModeEnabled = options.searchModeEnabled || false;
    var topicId = options.topicForBreadcrumb;

    data.attCardData = {};
    data.attCardData.iconClass = "fa fa-file-text-o";
    data.attCardData.type = gs.getMessage("Attachment");
    data.attCardData.isFeatured = isFeatured;
    data.attCardData.viewType = viewType;
    data.attCardData.widgetTitle = title;
    data.attCardData.widgetSysId = widgetSysId;
    data.attCardData.sysId = attSysId;
    data.attCardData.table = "sys_attachment";

    if (searchModeEnabled) {
        data.attCardData.title = options.title;
        data.attCardData.description = options.text;
        data.attCardData.image = options.image ? options.image + '?t=small' : '';
        data.attCardData.url = '?id=kb_article&sysparm_article=' + options.number;
        if(topicId){
            data.attCardData.url += '&topic_id='+topicId;
        }
        data.attCardData.additionalInfo = options.sys_updated_on;
        data.widgetData = $sp.getWidget("content-card", data.attCardData);
    }
    else {
        if (!attSysId || !attTable)
        return;

        var gr = new GlideRecordSecure(attTable);
        if (gr.get(attSysId)) {
            data.attCardData.title = gr.getDisplayValue('file_name');
            var description = gr.getDisplayValue('text');
            data.attCardData.description = !description ? '' : $sp.stripHTML(description);
            data.attCardData.image = gr.getDisplayValue('image') ? gr.getDisplayValue('image') + '?t=small' : '';
            data.attCardData.url = '?id=kb_article&sysparm_article=' + gr.getValue('number');
            if(topicId){
                data.attCardData.url += '&topic_id='+topicId;
            }
            data.attCardData.additionalInfo = gr.getDisplayValue('sys_updated_on');
            data.widgetData = $sp.getWidget("content-card", data.attCardData);
        } else
            return;
    }
})();

 

Then change the portal page to display the customised widget.

 

The OOB widget is only setup for Catalog items and KB articles, so if it's not the attachments that is causing the issue. I would do a $scope.data dump on the Topic Content widget and check the console to see what is missing, you'll find the table under aisSearchResults

JonathanTing_1-1689803564413.png

 

Jonathan Ting
Tera Guru

@rachana_patel did my post clear on why this was happening and help you resolve this issue of the blank cards?