Images are not displaying in the portal

sudha10
Mega Expert

Hello Experts,

 

We have to display the images of incident and RITM on the homepage of the portal. And used the below script to display the images. It is not working

 

if (gr.sys_class_name.toString() == "sc_req_item") {
f.aClass=gr.sys_class_name.toString();
if($sp.getCatalogItem(gr.getValue(name)).icon != undefined)
{
f.image = $sp.getCatalogItem(gr.getValue(name)).picture;
f.image = "incident.png";

}

var ge = gr.getElement(name);
if (ge) {
var ed = ge.getED();
if (ed)
f.type = ed.getInternalType();
f.label = ge.getLabel();
}
return f;
}

 


function getImageForCatalogItem(gr, name) {
var grImage = new GlideRecord("sys_attachment")
grImage.addQuery(table_sys_id, "f7b6b5b2dbd3b7003fefd7b7f4961970");
if (grImage.image != undefined)
f.image = grImage.image + "";
}

 

Recently studied one article saying that getCatalogItem method is deprecated. That's the reason it is not displaying the images. Please find the below information.

 

getCatalogItem(String sysId)

Returns a model and view model for a sc_cat_item or sc_cat_item_guide.

This method is deprecated. Use the getCatalogItem(String sysId, Boolean isOrdering) method instead. This method calls the getCatalogItem(String sysId, Boolean isOrdering) method with the isOrdering parameter set to false, which means that write roles security checking is done.

 

 

find_real_file.png

 

Could you please help me how to display the image in the portal which is not a static image.

 

Thanks alot in advance.

1 REPLY 1

Shane41
ServiceNow Employee
ServiceNow Employee

Hi Sudha,

Can you try the following function using the sys_id of the catalog item

var catalogItemJS = new sn_sc.CatItem(SYS_ID OF CATALOG ITEM);

var catItemDetails = catalogItemJS.getItemSummary();

f.image = catItemDetails.picture;

Hope this helps,

Shane