How to Add VIP visual indicator for “Requested for” on RITM (similar to Incident Caller VIP)

nameisnani
Mega Sage

Hi Team,

I have a requirement to visually highlight VIP users on the Requested Item (RITM) form.


📌 Requirement

On the Requested Item [sc_req_item] form:

  • Field: Requested for (requested_for)
  • If the selected user has VIP = true (in sys_user.vip):
    • Show a VIP icon / decoration on the field, and optionally
    • Change the field text color (e.g., red) to make it stand out
  • If the user is not VIP:
    • No VIP indicator / normal display

This needs to work both when:

  1. The RITM is opened (onLoad)
  2. The Requested for field is changed by the user (onChange)


can anyone please help me - how to achieve this requriment .

thanks in advance 

2 ACCEPTED SOLUTIONS

This is for sc_task.

1. Onload client script :

TanushreeMaiti_0-1771223254320.png

code: Client script (script include already shared)

function onLoad() {

var reqLabel = g_form.getLabel("request_item.requested_for");
var reqField = g_form.getDisplayBox("request_item.requested_for");
var innerHtml = "<span id=\"status.sc_task.request_item.requested_for\" title=\"On behalf of another individual\" mandatory=\"false\" oclass=\"\" aria-label=\"\" class=\" required-marker\"></span><span title=\"On behalf of another individual\" class=\"label-text\" data-html=\"false\">Requested for</span>";

if (!reqLabel || !reqField){
return;
}

if (g_form.getValue("request_item.requested_for")!=null){
if(!g_scratchpad.u_vip){
var ga = new GlideAjax('CallerVIP');
ga.addParam('sysparm_name','getVIP');
ga.addParam('sysparm_caller', g_form.getValue("request_item.requested_for"));
ga.getXMLAnswer(vipTaskCallback);
}
else {
vipTaskCallback(g_scratchpad);
}
}
else {
removeTaskVIPStyles(reqLabel, reqField);

}

function vipTaskCallback(requestedFor) {
if (!requestedFor.u_vip){
requestedFor = requestedFor.evalJSON();
}

//check for VIP status
if (requestedFor.u_vip.toString() == 'true') {
setTaskVIPStyles(reqLabel, reqField);
}
else {
removeTaskVIPStyles(reqLabel, reqField);
}

}

function setTaskVIPStyles(label, field){

if (label) {
label.innerHTML = "<img src='images/icons/vip.gif'/>" + label.innerHTML;

}
//change the caller's name field to red text
if (field) {
field.style.color='red';
}
}

function removeTaskVIPStyles(label, field){
if (label) {
label.innerHTML = innerHtml;
}
if (field) {
field.style.color = '';
}
}
}

 

3. Style on sc_task : do it same way as ritm is done.

Please mark this response as Helpful & accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

View solution in original post

@nameisnani 

It's an easy requirement.

I suggested to check OOTB client script on incident table

No need of GlideAjax and script Include

this client script should work for RITM

I simply made changes to the OOTB client script, changed script, changed table, field name and Did Insert and Stay

Then made "Isolate Script" = False

function onChange(control, oldValue, newValue, isLoading) {
	var callerLabel = $('label.sc_req_item.requested_for');
	var callerField = $('sys_display.sc_req_item.requested_for');
	if (!callerLabel || !callerField)
		return;
	
	if (!newValue) {
		callerLabel.setStyle({backgroundImage: ""});
		callerField.setStyle({color: ""});
		return;
	}
	g_form.getReference('requested_for', vipCallerCallback);
}

function vipCallerCallback(caller) {
	var callerLabel = $('label.sc_req_item.requested_for').down('label');
	var callerField = $('sys_display.sc_req_item.requested_for');
	if (!callerLabel || !callerField)
		return;
	
	//check for VIP status
	if (caller.vip == 'true') {
		var bgPosition = "95% 55%";
		if (document.documentElement.getAttribute('data-doctype') == 'true')
			bgPosition = "5% 45%";
			
		callerLabel.setStyle({backgroundImage: "url(images/icons/vip.gif)", backgroundRepeat: "no-repeat", backgroundPosition: bgPosition, paddingLeft: '30px' });
		callerField.setStyle({color: "red"});
	} else {
		callerLabel.setStyle({backgroundImage: ""});
		callerField.setStyle({color: ""});
	}
}

AnkurBawiskar_1-1771234665858.png

 

 

Output

AnkurBawiskar_2-1771234681926.png

 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

21 REPLIES 21

@Tanushree Maiti  As per your steps I have cfreated

 

scrpit include 

CS 

Style 

 

Cilent scritp 

function onLoad() {

    var reqLabel = g_form.getLabel("requested_for");
    var reqField = g_form.getDisplayBox("requested_for");

    var innerHtml = "<span id=\"status.sc_req_item.request.requested_for\" title=\"On behalf of another individual\" mandatory=\"false\" oclass=\"\" aria-label=\"\" class=\" required-marker\"></span><span title=\"On behalf of another individual\" class=\"label-text\" data-html=\"false\">Requested for</span>";

    if (!reqLabel || !reqField) {
        return;
    }


    if (g_form.getValue("requested_for") != null) {
        if (!g_scratchpad.u_vip) {
            var ga = new GlideAjax('callervip');
            ga.addParam('sysparm_name', 'getVIP');
            ga.addParam('sysparm_caller', g_form.getValue("requested_for"));
            ga.getXMLAnswer(vipItemCallback);
        } else {
            vipItemCallback(g_scratchpad);
        }
    } else {
        removeItemVIPStyles(reqLabel, reqField);

    }

    function vipItemCallback(requestedFor) {
        if (!requestedFor.u_vip) {
            requestedFor = requestedFor.evalJSON();
        }

        //check for VIP status
        if (requestedFor.u_vip.toString() == 'true') {
            //alert('is a VIP');
            setItemVIPStyles(reqLabel, reqField);
        } else {
            removeItemVIPStyles(reqLabel, reqField);
        }

    }


    function setItemVIPStyles(label, field) {

        if (label) {
            label.innerHTML = "<img src='images/icons/vip.gif'/>" + label.innerHTML;

        }
        //change the caller's name field to red text
        if (field) {
            field.style.color = 'red';
        }
    }

    function removeItemVIPStyles(label, field) {
        if (label) {
            label.innerHTML = innerHtml;
        }
        if (field) {
            field.style.color = '';
        }
    }
}

 

 

Script include 

var CallerVip = Class.create();
CallerVip.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getVIP: function() {

        var usr = this.getParameter('sysparm_caller');

        var gr = new GlideRecord('sys_user');
        gr.addQuery('sys_id', usr);
        gr.query();

        if (!gr.next()) {
            return new JSON().encode({ error: "User not found" });
        }

        return new JSON().encode({
            u_vip: gr.vip.toString(),
            u_locationDisp: gr.location.getDisplayValue(),
            u_location: gr.location.toString(),
            u_phone: gr.phone.toString()
        });
    },

    type: 'CallerVip'
});

 

Style -

nameisnani_0-1771232514338.png

 

 

but still not working 

nameisnani_1-1771232568167.png

 

 

could you please tell what was mistake here ?

Ensure Isolate script - you have not checked.

Now for testing, make a user as VIP user. 

Go to list view of RITM for that VIP user (requested for)..Check whether icon is coming or not.

Share the screen shot.

Please mark this response as Helpful & accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

@Tanushree Maiti 

nameisnani_0-1771234113653.png

 

 

list view 

nameisnani_1-1771234240788.png

 

while opening the record - not showing 

@nameisnani 

It's an easy requirement.

I suggested to check OOTB client script on incident table

No need of GlideAjax and script Include

this client script should work for RITM

I simply made changes to the OOTB client script, changed script, changed table, field name and Did Insert and Stay

Then made "Isolate Script" = False

function onChange(control, oldValue, newValue, isLoading) {
	var callerLabel = $('label.sc_req_item.requested_for');
	var callerField = $('sys_display.sc_req_item.requested_for');
	if (!callerLabel || !callerField)
		return;
	
	if (!newValue) {
		callerLabel.setStyle({backgroundImage: ""});
		callerField.setStyle({color: ""});
		return;
	}
	g_form.getReference('requested_for', vipCallerCallback);
}

function vipCallerCallback(caller) {
	var callerLabel = $('label.sc_req_item.requested_for').down('label');
	var callerField = $('sys_display.sc_req_item.requested_for');
	if (!callerLabel || !callerField)
		return;
	
	//check for VIP status
	if (caller.vip == 'true') {
		var bgPosition = "95% 55%";
		if (document.documentElement.getAttribute('data-doctype') == 'true')
			bgPosition = "5% 45%";
			
		callerLabel.setStyle({backgroundImage: "url(images/icons/vip.gif)", backgroundRepeat: "no-repeat", backgroundPosition: bgPosition, paddingLeft: '30px' });
		callerField.setStyle({color: "red"});
	} else {
		callerLabel.setStyle({backgroundImage: ""});
		callerField.setStyle({color: ""});
	}
}

AnkurBawiskar_1-1771234665858.png

 

 

Output

AnkurBawiskar_2-1771234681926.png

 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar  could you also please help me on sc_task table please