Catalog item icon to display in ESC widget

Ed Hefford
Tera Guru

Hi everyone,

I'm hoping what I'm trying to do is possible. I'm trying to see if I can get the icon or picture from a catalog item to display in a custom widget I've build. Ideally, I need to get the icon/picture to display in my left TD, on the related forms widget I've built. Currently running a GlideRecord query against the related sc items table which displays on my cat item page.

 

 

Here's my server script:

 

(function () {
    var cat_item = $sp.getParameter('sys_id');
        data.catList = [];

    // Query related items
        var catalogRec = new GlideRecord('sc_2_sc');
    catalogRec.addQuery('sc_cat_item', cat_item);
    catalogRec.orderBy('related_sc_cat_item');
    catalogRec.query();

    while (catalogRec.next()) {
        var temp = {};
        temp.name = catalogRec.getDisplayValue('related_sc_cat_item');
        temp.short_description = catalogRec.getDisplayValue('related_sc_cat_item.short_description');
                temp.sys_id = catalogRec.getValue('related_sc_cat_item');
                temp.catIcon = catalogRec.getDisplayValue('related_sc_cat_item.picture');
            data.catList.push(temp);
    }

})();

 

 

No matter what I try, I cannot get the icon or picture relating to the catalog item itself to display in the widget. Any help or guidance would be appreciated.

Thanks, Ed

 

3 REPLIES 3

Allen Andreas
Administrator
Administrator

Hi,

How are you rendering it in your HTML?

The value you'd get back would be the sys_id of the sys_attachment record of the picture, plus something like: .iix

In your HTML, you'd want to consider rendering the image like: 

 

<img src=/sys_attachment.do?sys_id=" + obj.catIcon + ">

 

I would perhaps just use getValue as well, using the method I listed, instead of getDisplayValue.

See if that helps?


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Ed Hefford
Tera Guru

Hi Allen,

Thanks for your advice. We managed to get it working, and it was the case of adjusting the HTML side of things. 

This is what we used in the end:

<img ng-src="{{relatedItem.icon}}" src="{{relatedItem.icon}}" width="35px" height="35px">

EdHefford_0-1710971592434.png

Works really nicely! Thanks again for your advice!

Hi  @Ed Hefford 

Awesome! Glad you got it resolved.

If you don't mind and if you get time, please mark my reply above as "Accept Solution" if it helped guide you correctly.

Thanks for confirming and take care! ðŸ˜€


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!