- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2023 07:24 AM
Hello Experts,
I want to highlight requested for field on request table and Ritm table as well as on Catalog task table. I wrote the Client script but it was not working. Could you please help on this.
function onLoad() {
var callerLabel = $('label.sc_task.request_item.request.requested_for');
var callerField = $('sys_display.sc_task.request_item.request.requested_for');
if (!callerLabel || !callerField)
return;
/*if (!newValue) {
callerLabel.setStyle({backgroundImage: ""});
callerField.setStyle({color: ""});
return;
}*/
g_form.getReference('request_item.request.requested_for', vipCallerCallbackREQ);
}
function vipCallerCallbackREQ(caller) {
var callerLabel = $('label.sc_task.request_item.request.requested_for').down('label');
var callerField = $('sys_display.sc_task.request_item.request.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' });
//set callerField color
callerField.setStyle({color: "red"});
} else {
callerLabel.setStyle({backgroundImage: ""});
callerField.setStyle({color: ""});
}
}
@Ankur Bawiskar @Sohail Khilji
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 03:13 AM
Hi ,
You can create a on change Client script for the requested for field and use below script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2023 07:31 AM
Hello @AK79
Please find the below one.
function onLoad() {
//Type appropriate comment here, and begin script below
//Type appropriate comment here, and begin script below
var caller = g_form.getReference('mapping_requested_for', highlightVIP);
function highlightVIP(caller) {
if (caller.getValue('vip') == 'true') {
g_form.showFieldMsg('mapping_requested_for', getMessage("VIP User"), 'error');
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2023 01:45 PM - edited 06-19-2023 01:46 PM
Hi,
Use the below client script.
function onLoad() {
var callerLabel = $('label.sc_req_item.request.requested_for');
var callerField = $('sys_display.sc_req_item.request.requested_for');
if (!callerLabel || !callerField)
return;
var ga = new GlideAjax("userDetail");
ga.addParam("sysparm_name", "vip");
ga.addParam("sysparm_reqFor", "true");
ga.addParam("sysparm_request", g_form.getUniqueValue());
ga.getXML(vipCallBack);
function vipCallBack(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var callerLabel = $('label.sc_req_item.request.requested_for').down('label');
var callerField = $('sys_display.sc_req_item.request.requested_for');
if (!callerLabel || !callerField)
return;
//check for VIP status
if (answer == 'true') {
var bgPosition = "95% 55%";
if (document.documentElement.getAttribute('data-doctype') == 'true')
bgPosition = "20% 70%";
callerLabel.setStyle({
backgroundImage: "url(images/icons/vip.gif)",
backgroundRepeat: "no-repeat",
backgroundPosition: bgPosition,
paddingLeft: '30px'
});
//set callerField color
callerField.setStyle({
color: "red"
});
} /*else {
callerLabel.setStyle({
backgroundImage: ""
});
callerField.setStyle({
color: ""
});
}*/
}
}
Use the below script include function
vip: function() {
var field = this.getParameter("sysparm_reqFor");
var itemId = this.getParameter("sysparm_request");
var item = new GlideRecord("sc_req_item");
item.get(itemId);
if (field == "true")
return item.request.requested_for.vip;
if (field == "false")
return item.opened_by.vip;
},
Regards,
Deepankar Mathur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2023 11:40 PM
Hi @dmathur09 ,
I tried the same, but it is not working.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 04:05 AM
Can you let us know what error you are receiving. Can you confirm if you are getting the VIP flag correctly from the script include?
Client script should be working as expected.
Regards,
Deepankar Mathur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 12:07 AM - edited 06-20-2023 12:08 AM
See if this helps !
function onLoad() {
var requestedForField = g_form.getReferenceElement('requested_for');
if (requestedForField) {
var requestedFor = g_form.getValue('requested_for');
// Add your condition to determine VIP status
var isVIP = isUserVIP(requestedFor);
if (isVIP) {
requestedForField.style.backgroundColor = '#FFFF99'; // Apply desired highlight color
}
}
}
function isUserVIP(userId) {
// Implement your logic to determine if the user is a VIP
// Example: Check a user VIP field or query a user table to validate VIP status
// Return true if the user is a VIP, otherwise return false
return false;
}
Change the code were ever needed and it must work!
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....