Ankur Bawiskar
Tera Patron
Tera Patron

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

find_real_file.png

2) Catalog Client Script: Isolate Script -> False

find_real_file.png

3) RITM Form when User is VIP showing the icon

find_real_file.png

4) TASK Form when User is VIP showing the icon

find_real_file.png

5) User "Abel Tuter" is VIP User

find_real_file.png

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

5 Comments
John Vo1
Tera Guru

This works really good.  Thanks Ankur!!

Priya Shid1
Kilo Guru

Looking for the same .Thank you!!!

Nagashree5
Tera Contributor

How can we do this if we want to highlight the sc_req_item and task table "Requested for" filed if VIP is user is selected. Like the same we have for Incident Caller.

Isac Newton Gab
Tera Contributor

Hello,

 

How to remove the icon once based on a condition?

Thanks.

Pratik Vishvaka
Giga Explorer

Hi 

1)This Script is working for Onchange (type).

2) If admin want to rise some request behalf of any other user it will work for this also.

3)If you want to remove VIP tag when the User is not VIP (VIP=False).

 

 

function onChange(control, oldValue, newValue, isLoading) {
    // if the caller_id field is not present, then we can't add an icon anywhere
  var user = g_form.getReference('u_requested_by', callBackMethod);   
}

function callBackMethod(u_requested_by) {

    if (u_requested_by.vip.toString() == 'true') {
        var variableQuestionValue = 'Requested for';
		$j('span[id^="vipflag"]').remove();
        $j("<span id='vipflag'><img src='images/icons/vip.gif'></span>").insertAfter("span.sn-tooltip-basic:contains(" + variableQuestionValue + ")");
    }
	else
		{
        $j('span[id^="vipflag"]').remove();
		}
}