logo

NJP

VIP Icon on Catalog Variable

Import · Apr 19, 2020 · article

I have seen few questions wherein users require a VIP Icon for catalog variable when the user is a VIP user..

Use case: Consider you have a Variable which refers to "sys_user" table. When the Request Item form loads or Catalog Task form loads and if the User variable holds a VIP User then vip icon should be visible besides the variable.

Approach:

1) Create an onLoad Catalog Client Script which is set to "Applies on Requested Items" and "Applies on Catalog Tasks"

2) Use Script mentioned below; ensure you give question value in script inside the Contains filter and not the name. Using g_form.getControl() doesn't work on sc_req_item and sc_task tables.

3) Ensure Isolate Script field is set to False for the above Catalog Client Script; this field can be edited from List

Script:

function onLoad() {
    //Type appropriate comment here, and begin script below
    var user = g_form.getReference('user', callBackMethod);
}

function callBackMethod(user){

    if(user.vip.toString() == 'true'){
        var variableQuestionValue = 'User';
        $j("<img src='images/icons/vip.gif'>" ).insertAfter("span.sn-tooltip-basic:contains(" + variableQuestionValue + ")");
    }
}

Screenshots:

1) Variable Question with Value as User being used inside the script

image

2) Catalog Client Script: Isolate Script -> False

image

3) RITM Form when User is VIP showing the icon

image

4) TASK Form when User is VIP showing the icon

image

5) User "Abel Tuter" is VIP User

image

Note: If you would like to test this; try changing the value to a user who is not VIP and the icon should not show up

Additionally you can also highlight the background in red/orange color as below

g_form.getDisplayBox('user').style.backgroundColor =  'orange';

You can also show the text in red color as below

g_form.getDisplayBox('user').style.color= 'red';

Thanks for reading the blog and do provide your inputs/suggestions if any.

Hope you find this article helpful. Don’t forget to Mark it Helpful, Bookmark.Thanks,

Ankur Bawiskar

ServiceNow MVP 2020,2019,2018

My Articles & Blogs

View original source

https://www.servicenow.com/community/developer-blog/vip-icon-on-catalog-variable/ba-p/2286828