Need to show VIP icon beside the requested for into the loaner order table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2025 07:44 AM
Hi Team,
I need to display the VIP icon beside "requested for" in the Loaner Asset Order table (sn_hamp_loaner_asset_order), which is part of the scoped application "Hardware Asset Management".
I have created an on-load client script on the (sn_hamp_loaner_asset_order) table where I can fetch the values from the script include, but I think "document.getElementsByClassName" is not working due to scoped application.
function onLoad() {
alert("Loaner VIP");
var ga = new GlideAjax('global.gsUtils');
var reqFor = g_form.getValue('requested_for');
ga.addParam('sysparm_name', 'getUser');
ga.addParam('sysparm_user', reqFor);
ga.getXML(callback);
function callback(response) {
alert("Loaner VIP Callback");
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
var user = JSON.parse(answer); //convert the json formatted string that is returned to an object
alert(" Line 14");
var reqforLabel = document.getElementsByClassName('col-xs-12 col-md-3 col-lg-4 control-label')[1]; //This label is the 2nd on the form
alert("Line 15");
var reqforField = document.getElementById('sys_display.sn_hamp_loaner_asset_order.requested_for');
alert("Loaner VIP 3");
if (user.vip == '1' || user.vip == 1 || user.vip == true) {
reqforLabel.setStyle({
backgroundImage: "url(images/icons/vip.gif)",
backgroundRepeat: "no-repeat",
backgroundPosition: "5% 45%"
});
reqforField.style.color = 'red';
} else {
reqforLabel.style.backgroundImage = '';
reqforField.style.color = '';
}
}
}
After the line number 14 code is not running, can someone please help me here what is the issue?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2025 08:05 AM - edited 05-29-2025 08:15 AM
Hi @lucky24 ,
Uncheck the Isolate script check box and try
try that and see
try this script if still doesn't work
keep lsolate script = false(unchecked)
use script
function onLoad() {
var reqforLabel = $('label.sn_hamp_loaner_asset_order.requested_for');
var reqforField = $('sys_display.sn_hamp_loaner_asset_order.requested_for');
if (!reqforLabel || !reqforField)
return;
var ga = new GlideAjax('global.gsUtils');
var reqFor = g_form.getValue('requested_for');
ga.addParam('sysparm_name', 'getUser');
ga.addParam('sysparm_user', reqFor);
ga.getXMLA(vipCallerCallback);
}
function vipCallerCallback(user) {
var reqforLabel = $('label.sn_hamp_loaner_asset_order.requested_for').down('label');
var reqforField = $('sys_display.sn_hamp_loaner_asset_order.requested_for');
if (!reqforLabel || !reqforField)
return;
//check for VIP status
if (user.vip == '1' || user.vip == 1 || user.vip == 'true' || user.vip == true) {
var bgPosition = "95% 55%";
if (document.documentElement.getAttribute('data-doctype') == 'true')
bgPosition = "5% 45%";
reqforLabel.setStyle({backgroundImage: "url(images/icons/vip.gif)", backgroundRepeat: "no-repeat", backgroundPosition: bgPosition, paddingLeft: '30px' });
reqforField.setStyle({color: "red"});
} else {
reqforLabel.setStyle({backgroundImage: ""});
reqforField.setStyle({color: ""});
}
}
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2025 08:36 AM
ensure Isolate Script = False for your client script.
Also for your reference you can refer the OOTB incident table client script for VIP
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader