- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2025 12:50 AM
Hi All ,
In sc_req_item table. when we open a form for an existing record then if requested for user is vip then the vip icon should display left to the field. But i tried the script and it was not working. Hence kindly help someone and correct the code if i missed anything.
Note : i unchecked isolate script checkbox.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2025 01:44 AM
you didn't copy the code correctly from the OOTB incident VIP caller client script
Also that OOTB client script is onChange but you want onLoad so couple of lines I removed
Working Script:
function onLoad() {
var callerLabel = $('label.sc_req_item.requested_for');
var callerField = $('sys_display.sc_req_item.requested_for');
if (!callerLabel || !callerField)
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: ""
});
}
}
Output:
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2025 01:28 AM - edited 05-27-2025 01:29 AM
did you debug by adding alert?
is that field requested_for available on the form and is populated?
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2025 01:44 AM
you didn't copy the code correctly from the OOTB incident VIP caller client script
Also that OOTB client script is onChange but you want onLoad so couple of lines I removed
Working Script:
function onLoad() {
var callerLabel = $('label.sc_req_item.requested_for');
var callerField = $('sys_display.sc_req_item.requested_for');
if (!callerLabel || !callerField)
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: ""
});
}
}
Output:
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2025 01:52 AM
Hi @suresh kaliappa ,
Make it onChange and uncheck the isolate script
Refer screenshot below
script:
function onChange(control, oldValue, newValue, isLoading) {
var reqForLabel = $('label.sc_req_item.requested_for');
var reqForField = $('sys_display.sc_req_item.requested_for');
if (!reqForLabel || !reqForField)
return;
if (!newValue) {
reqForLabel.setStyle({
backgroundImage: ""
});
reqForField.setStyle({
color: ""
});
return;
}
g_form.getReference('requested_for', vipCallerCallback);
}
function vipCallerCallback(caller) {
var reqForLabel = $('label.sc_req_item.requested_for').down('label');
var reqForField = $('sys_display.sc_req_item.requested_for');
if (!reqForLabel || !reqForField)
return;
//check for VIP status
if (caller.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