Help with the SC Catalog Item widget

sarahyelton
Tera Expert

I am trying to use the SC Catalog Item widget and its just not working.  I read on another thread that I had to clone the widget and then modify the code for the server script to include the homepage ID and the sys ID for the item.  It is still showing the item not found error.

find_real_file.png

Here is the server side script.  What am I doing wrong or not doing?????  

// populate the 'data' variable with catalog item, variables, and variable view
(function() {
// portal can specify a catalog and catalog category home page
data.sc_catalog_page = $sp.getDisplayValue("sc_catalog_page") || "sc_home";
data.sc_category_page = $sp.getDisplayValue("sc_category_page") || "sc_category";

options.show_add_cart_button = (options.show_add_cart_button == "true");

if (options.page) {
var pageGR = new GlideRecord("sp_page");
options.page = (pageGR.get(options.page)) ? pageGR.getValue("id") : null;
}

if (options.table) {
var tableGR = new GlideRecord("sys_db_object");
options.table = (tableGR.get(options.table)) ? tableGR.getValue("name") : null;
}

var page = 'it_homepage'
var sys_id = 'ed8026b7dbe51700b7a85458dc96190f'
options.url = options.url || "?id={page}&table={table}&sys_id={sys_id}";
data.showPrices = $sp.showCatalogPrices();
var m = data.msgs = {};
m.submitMsg = gs.getMessage("Submit");
m.submittedMsg = gs.getMessage("Submitted");
m.createdMsg = gs.getMessage("Created");
m.trackMsg = gs.getMessage("track using 'Requests' in the header or");
m.clickMsg = gs.getMessage("click here to view");
m.dialogTitle = gs.getMessage("Delete Attachment");
m.dialogMessage = gs.getMessage("Are you sure?");
m.dialogOK = gs.getMessage("OK");
m.dialogCancel = gs.getMessage("Cancel");
m.largeAttachmentMsg = gs.getMessage("Attached files must be smaller than {0} - please try again", "24MB");
m.renameSuccessMsg = gs.getMessage("Attachment renamed successfully");
m.deleteSuccessMsg = gs.getMessage("Attachment deleted successfully");

if (input)
data.sys_id = input.sys_id;
else if (options.sys_id)
data.sys_id = options.sys_id;
else
data.sys_id = $sp.getParameter("sys_id") || $sp.getParameter('sl_sys_id');

if (!data.sys_id)
return;

data._generatedItemGUID = gs.generateGUID();
var validatedItem = new sn_sc.CatItem('' + data.sys_id);
if (!validatedItem.canView())
return;

data.sc_cat_item = $sp.getCatalogItem(data.sys_id, true);
if (data.sc_cat_item.category) {
var categoryJS = new sn_sc.CatCategory(data.sc_cat_item.category);
data.category = {
name: categoryJS.getTitle(),
url: '?id='+data.sc_category_page+'&sys_id=' + data.sc_cat_item.category
}
}

var athTblName = 'sp_portal';
var className = data.sc_cat_item.sys_class_name;
if (!new global.CatalogItemTypeProcessor().canCreateNormalCartItem(className)) {
if (className == 'sc_cat_item_producer') {
var gr = new GlideRecord('sc_cat_item_producer');
gr.get(data.sys_id);
if (gr.isValidRecord())
athTblName = gr.getValue('table_name');
}
}
data._attachmentTable = athTblName;

$sp.logStat('Catalog View', data.sc_cat_item.sys_class_name, data.sys_id, data.sc_cat_item.name);
})()

4 REPLIES 4

ryanlitwiller
Giga Guru

What version are you on? Can you use the F12 browser inspection tools to see if your widget is consoling any errors? Once you open the console CTRL+Right Click on the widget and console log the $scope.data.

Any chance this is a record producer? I've have record producer not show up due to a miss match in the field type from the record producer variables and the table columns.

We are on Jakarta currently.  It is not a record producer, although I would like to know how to handle those in the future.  We are currently building out our first service portal and I know we would like to feature some items eventually that are record producers.  This is what the console gave me.  Is this what you needed to see?  Thank you for your help.

Failed to load resource: the server responded with a status of 404 (Not Found)
js_includes_sp_desigT_2018&c=4_49:66091 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
2
js_includes_sp_desigT_2018&c=4_49:26732 amb.MessageClient [INFO] >>> connection exists, request satisfied
js_includes_sp.jsx?vT_2018&c=4_49:12105 >>> init incident?caller_id=javascript:gs.getUserID()^active=true
js_includes_sp_desigT_2018&c=4_49:26732 amb.MessageClient [INFO] >>> connection exists, request satisfied
js_includes_sp.jsx?vT_2018&c=4_49:66337 Widget $scope.data...
  1. {msgs: {…}, sys_id: null, showPrices: false, sc_catalog_page: "sc_home", sc_category_page: "sc_category"}
    1. msgs:{largeAttachmentMsg"Attached files must be smaller than 24MB - please try again"renameSuccessMsg"Attachment renamed successfully"submittedMsg"Submitted"deleteSuccessMsg"Attachment deleted successfully"dialogMessage"Are you sure?", …}
    2. sc_catalog_page:"sc_home"
    3. sc_category_page:"sc_category"
    4. showPrices:false
    5. sys_id:null
    6. __proto__:Object

A screenshot would be easier. Can you share the url you have when your getting item not found? Most of the widgets rely on url parameters to retrieve records.

Can you search for the catalog item?

I would revert your changes and try navigating to this url:

https://[YOUR INSTANCE].service-now.com/[YOUR SP URL]?id=it_homepage&sys_id=ed8026b7dbe51700b7a85458dc96190f

sarahyelton
Tera Expert

Here is the screenshot with console.

 When I use the URL format you provided, the widget displays properly.  What do I change on the widget to ensure it works?