Possible to filter Top Searches widget?

jangunnar
Kilo Contributor

We have customers using our ServiceNow instance with limited access, ensuring they can only open their own records.

However the Top Searches widget will show search terms from all users, not just those in their own company. Ofcourse re-using the search terms will limit them to their own set of data, but the problem is the search term themselves contains information that we do not want to be shared between our users in the same instance.

I tried searching for a solution, I know there is both a secheduled task and something around ts_query.list that governs this.

But how would I go about to add a filter so that the widget will only return top search results from users having the same company as current user?

4 REPLIES 4

sndangibbard
Mega Guru

Jan,



Can you please specify which widget/area of the platform you are referring to?


find_real_file.png



find_real_file.png



These


I think you are looking for this table "text_search". I m not sure if you can apply filters on them but you can definitely create a new one


Paul Curwen
Giga Sage

Hi,

 

You can filter which tables are included in the text search widget using this system property:

 

glide.ts.widget.top_search_tables

 

just amend the value field as needed e.g. 

 

kb_knowledge,problem,incident,change_request,sc_cat_item

 

You can also adjust what's included by amending the widget script called 'Text Search'

you will find this under System UI > Widgets then search for Name = 'text search'

 

You can see the code is fairly simple: 

 

function sections() {
   var widgetTypes = {};
   widgetTypes["Top Searches"] = topSearchSections();
   // add any other types of text search widgets here
   return widgetTypes;
}

function topSearchSections() {
    var widgetTypes = {};
    var widgetName = "Top Searches - All";
    widgetTypes[widgetName] = generateTopSearchSectionObject(widgetName, "top", "");
    var propertyName = "glide.ts.widget.top_search_tables";
    var tablesProperty = gs.getProperty(propertyName);
    if (tablesProperty != "") {
       var tables = tablesProperty.split(",");
       for (var i=0; i < tables.length; i++) {
          var tableName = tables[i];
          var gr = new GlideRecord(tableName);
          if (!gr.isValid()) {
             gs.log("Text Search table \"" + tableName + "\" specified by " + propertyName + " is not a valid table; skipping");
             continue;
          }
      
          widgetName = "Top Searches - " + gr.getLabel();
          widgetTypes[widgetName] = generateTopSearchSectionObject(widgetName, "top", tableName);
       }
    }
    return widgetTypes;
}

function generateTopSearchSectionObject(widgetName, widgetType, tableName) {
   return { "type" : widgetType, "table" : tableName };
}

function render() {
	var type = renderer.getPreferences().get("type");
        var tableName = renderer.getPreferences().get("table");
        var gf = new GlideForm(renderer.getGC(), "render_gadget_text_searches_" + type, 0);
        gf.setDirect(true);
        gf.setRenderProperties(renderer.getRenderProperties());
        return gf.getRenderedPage();
}

function getEditLink() {
   return ""; // no edit
}

 

 

***If Correct/Helpful please take time mark as Correct/Helpful. It is much appreciated.***

Regards

Paul