Portal search not returning catalog items after upgrade

castle11
Tera Expert

We have just upgraded all of our instances to Vancouver and have discovered that our service portal is no longer returning any catalog items when searching for them. KB's are being returned only. Looking at the logs, I can see an error when searching

"queryLocation" is not defined. sp_search_source...."

It's referring to the queryLocation variable in the data fetch script within the "Catalogs" search source. I compared the script with the ootb version in my PDI and they're both the same - here it is for reference:

var indexGroup = (typeof indexGroup !== "undefined") ? indexGroup : "portal_index_group";
(function(query, indexGroup, queryLocation) {
    // To support pagination. The value set to the key query_location on the last item is available in the next iteration here
    queryLocation = queryLocation || 0;
    var limitCount = data.limit;
    var results = [];
    //Here goes the logic. Compute results however you want!
    if (!gs.isLoggedIn())
        return results;

    var taxonomyId = $sp.getTaxonomies();
    var sc;
    if (taxonomyId) {
        //For taxonomy topic based search send catalogs and categories as empty .
        sc = new sn_sc.CatalogSearch().search('', '', query);
        sc.addQuery('taxonomy_topic.active', true);
        sc.addQuery('taxonomy_topic.taxonomy', taxonomyId);
        sc.addQuery('sys_class_name', 'NOT IN', 'sc_cat_item_wizard');
        sc.addEncodedQuery('hide_sp=false^ORhide_spISEMPTY');
        if (facets.topic)
            sc.addQuery("taxonomy_topic", "IN", facets.topic.join(","));
    } else {
        var portalValue = $sp.getCatalogs().value;
        sc = new sn_sc.CatalogSearch().search(portalValue, '', query);
        sc.addQuery('sys_class_name', 'NOT IN', 'sc_cat_item_wizard');
        sc.addEncodedQuery('hide_sp=false^ORhide_spISEMPTY');
        if (facets.category)
            sc.addQuery("category", "IN", facets.category.join(","));
        if (facets.catalog)
            sc.addQuery("sc_catalogs", "CONTAINS", facets.catalog);
    }

    if (indexGroup)
        sc.addQuery('123TEXTINDEXGROUP321', indexGroup);

    var newLimitCount = queryLocation + limitCount;
    sc.query();
    var catCount = 0;
    while (sc.next() && catCount < newLimitCount + 1) {
        var catalog_item = new sn_sc.CatItem(sc.getUniqueValue());
        var category = catalog_item.getFirstAccessibleCategoryForSearch(facets.catalog ? facets.catalog : portalValue);
        var canViewItem = catalog_item.canViewOnSearch();
        if (!taxonomyId && !category)
            canViewItem = false;

        if (!canViewItem)
            continue;

        // We compute the first k + r and return the last r items
        if (catCount < queryLocation) {
            catCount++;
            continue;
        }

        var item = {};
        item.type = "sc"; // supported types are "sc" and "sc_content"
        item.page = "sc_cat_item";
        item.table = "sc_cat_item"; // populate the table name for analytics
        if (sc.getRecordClassName() == "sc_cat_item_guide")
            item.page = "sc_cat_item_guide";
        else if (sc.getRecordClassName() == "sc_cat_item_content") {
            var gr = new GlideRecord('sc_cat_item_content');
            gr.get(sc.getUniqueValue());
            $sp.getRecordValues(item, gr, 'url,content_type,kb_article');
            item.type = "sc_content";
        }

        $sp.getRecordDisplayValues(item, sc, 'name,short_description,sys_id,sys_class_name');

        item['picture'] = catalog_item.getPicture();
        item['icon'] = catalog_item.getIcon();
        item['price'] = catalog_item.getCompleteItemPrice();
        item.score = parseInt(sc.ir_query_score.getDisplayValue());
        item.label = item.name;
        item.primary = item.name;
        // determine URL/target and default icon in case item has no picture/icon
        if (item.type == "sc") {
            item.url = '?id=' + item.page + '&sys_id=' + item.sys_id;
            item.default_icon = "folder-open-o";
        } else if (item.type == "sc_content") {
            item.default_icon = "book";
            if (item.content_type == "kb") {
                item.url = '?id=kb_article&sys_id=' + item.kb_article;
                item.default_icon = "file-text-o";
            } else if (item.content_type == "external") {
                item.url = item.url + "";
                item.target = '_blank';
            } else
                item.url = '?id=sc_cat_item&sys_id=' + item.sys_id;
        }

        item['query_location'] = catCount;
        results.push(item);
        catCount++;
    }

    if (!data.includeFacets)
        $sp.logSearch('sc_cat_item', query, sc.getRowCount(), data.searchType, data.portal, data.page);

    // We have populated one extra to know if it is the last result in the list
    if (results.length !== 0) {
		if (results.length > limitCount)
			results.pop();
		else
			results[results.length - 1].isLastResult = true;
    }

    return results;
})(query, indexGroup, queryLocation);

I have also double checked some fields on the catalog items such as visible elsewhere, hide on serviceportal, and no search, and they are all set correctly. Any suggestions? I put the script into a JS validator and it also states that queryLocation is not defined, but again this is the same in the ootb script, so I suspect whatever is being fed into the script is the issue.

5 REPLIES 5

Eswar Chappa
Mega Sage
Mega Sage

Hi @castle11 

 

Please give a try with the below solution once

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0752322

 

Thanks & Regards,

Eswar Chappa

Mark my answer correct and Helpful if this helps you ðŸ˜€

Hi Eswar,

 

Thanks for your response - we had tried indexing as well but it turns out the issue was caused as part of the upgrade and was fixed in subsequent patches.

We're having same issue after our Vancouver upgrade. Reindexing did not fix for us either.

Make sure to install all patches after upgrade as this was fixed by ServiceNow