- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Team,
I have a requirement to visually highlight VIP users on the REQ and RITM
Requirement
On the REQ and 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:
- The RITM and REQ is opened (onLoad)
- The Requested for field is changed by the user (onChange)
I have created client script for both tables
for REQ it is working fyn - VIP is highlighting
for RITM it is not working
client script for ritm
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: ""});
}
}
O/P
what was the mistake in my script
@Ankur Bawiskar - i have configured as per your scritpt provided here ( https://www.servicenow.com/community/developer-forum/how-to-add-vip-visual-indicator-for-requested-f...)
could u please help me here @Ankur Bawiskar
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi @nameisnani ,
This is definitely something I missed, so apologies for that. An important piece on how client scripts work is that they only will work if the field is on the form, which is why you're seeing that behavior. The only option in the "Field name" field on the client script form is referencing the requested_for on the sc_req_item table and not the dot-walked field (request.requested_for).
I've adjusted the script to be an onLoad instead and that seemed to work in my PDI. Unfortunately, the user experience will not be as great and the page will have to be loaded in order to see the change.
Please let me know if this accomplishes what you're looking for and mark my answer as correct if it solves your issue.
function onLoad() {
var requestedForLabel = $('label.sc_req_item.request.requested_for');
var requestedForField = $('sys_display.sc_req_item.request.requested_for');
if (!requestedForLabel || !requestedForField)
return;
g_form.getReference('request.requested_for', vipCallback);
}
function vipCallback(requestedFor) {
if (!requestedFor) {
requestedForLabel.setStyle({backgroundImage: ""});
requestedForField.setStyle({color: ""});
return;
}
var requestedForLabel = $('label.sc_req_item.request.requested_for').down('label');
var requestedForField = $('sys_display.sc_req_item.request.requested_for');
if (!requestedForLabel || !requestedForField)
return;
//check for VIP status
if (requestedFor.vip == 'true') {
var bgPosition = "95% 55%";
if (document.documentElement.getAttribute('data-doctype') == 'true')
bgPosition = "45% 90%";
//bgPosition = "5% 45%";
requestedForLabel.setStyle({backgroundImage: "url(images/icons/vip.gif)", backgroundRepeat: "no-repeat", backgroundPosition: bgPosition, paddingLeft: '30px' });
requestedForField.setStyle({color: "red"});
} else {
requestedForLabel.setStyle({backgroundImage: ""});
requestedForField.setStyle({color: ""});
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@Robert Perrone @Ankur Bawiskar
If i remove requested_for from form layout - then VIP tag is not coming -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi @nameisnani ,
This is definitely something I missed, so apologies for that. An important piece on how client scripts work is that they only will work if the field is on the form, which is why you're seeing that behavior. The only option in the "Field name" field on the client script form is referencing the requested_for on the sc_req_item table and not the dot-walked field (request.requested_for).
I've adjusted the script to be an onLoad instead and that seemed to work in my PDI. Unfortunately, the user experience will not be as great and the page will have to be loaded in order to see the change.
Please let me know if this accomplishes what you're looking for and mark my answer as correct if it solves your issue.
function onLoad() {
var requestedForLabel = $('label.sc_req_item.request.requested_for');
var requestedForField = $('sys_display.sc_req_item.request.requested_for');
if (!requestedForLabel || !requestedForField)
return;
g_form.getReference('request.requested_for', vipCallback);
}
function vipCallback(requestedFor) {
if (!requestedFor) {
requestedForLabel.setStyle({backgroundImage: ""});
requestedForField.setStyle({color: ""});
return;
}
var requestedForLabel = $('label.sc_req_item.request.requested_for').down('label');
var requestedForField = $('sys_display.sc_req_item.request.requested_for');
if (!requestedForLabel || !requestedForField)
return;
//check for VIP status
if (requestedFor.vip == 'true') {
var bgPosition = "95% 55%";
if (document.documentElement.getAttribute('data-doctype') == 'true')
bgPosition = "45% 90%";
//bgPosition = "5% 45%";
requestedForLabel.setStyle({backgroundImage: "url(images/icons/vip.gif)", backgroundRepeat: "no-repeat", backgroundPosition: bgPosition, paddingLeft: '30px' });
requestedForField.setStyle({color: "red"});
} else {
requestedForLabel.setStyle({backgroundImage: ""});
requestedForField.setStyle({color: ""});
}
}
