Making the VIP name red in a task table Requested for field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2024 02:45 AM
Hi Team,
I want to make the Requested for field for VIP names in red on a task table , but reqested for is not the direct field on TASK table how can i achieve it by using the client scrip.
Note: Requested for on sc table field info: Dictionary Info: sc_task.request_item.requested_for
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2024 08:01 PM - edited 01-02-2024 08:03 PM
Hi @raj99918
Since you're working with OnLoad Client Script. The newValue from your script below is not defined.
You can try my adjustment below.
1. Remove the lines related to newValue
2. Correct the variable name
3. Change the background attribute.
function onLoad() {
var requestedForLabel = $('label.sc_task.request_item.requested_for');
var requestedForField = $('sys_display.sc_task.request_item.requested_for');
if (!requestedForLabel || !requestedForField)
return;
//The newValue below is undefined
/*if (!newValue) {
requestedForLabel.setStyle({
backgroundImage: ""
});
requestedForField.setStyle({
color: ""
});
return;
}*/
//Correct the field name below
g_form.getReference('request_item.requested_for', viprequestedForCallback);
}
function viprequestedForCallback(requestedFor) {
var requestedForLabel = $('label.sc_task.request_item.requested_for').down('label');
var requestedForField = $('sys_display.sc_task.request_item.requested_for');
if (!requestedForLabel || !requestedForField)
return;
//check for VIP status
if (requestedFor.vip.toString() == 'true') {
var bgPosition = "95% 55%";
if (document.documentElement.getAttribute('data-doctype') == 'true')
bgPosition = "5% 45%";
requestedForLabel.setStyle({
backgroundImage: "url(images/icons/vip.gif)",
backgroundRepeat: "no-repeat",
backgroundPosition: bgPosition,
paddingLeft: '30px'
});
requestedForField.setStyle({
//color: "red"
background: "red" //change to background attribute
});
} else {
requestedForLabel.setStyle({
backgroundImage: ""
});
requestedForField.setStyle({
//color: ""
background: "" //change to background attribute
});
}
}
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2024 12:28 PM
Hi @Timi,
Thanks for the reply. I have modified the onLoad script similar to what you have given so VIP icon is coming but VIP name in requested for is not showing in RED color. Below is my modified script:
function onLoad() {
var callerLabel = $('label.sc_task.request_item.requested_for');
var callerField = $('sys_display.sc_task.request_item.requested_for');
if (!callerLabel || !callerField)
return;
// if (!newValue) {
// callerLabel.setStyle({backgroundImage: ""});
// callerField.setStyle({color: ""});
// return;
// }
g_form.getReference('request_item.requested_for', vipCallerCallbackREQ);
}
function vipCallerCallbackREQ(caller) {
var callerLabel = $('label.sc_task.request_item.requested_for').down('label');
var callerField = $('sys_display.sc_task.request_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: ""});
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2024 07:39 PM
Hi @raj99918
I copy exactly your script above, and it totally works fine for me.
Make sure the Isolate script checkbox is unchecked. And also the field name "request_item.requested_for" is correct.
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 02:09 AM
Hi @Tai Vu I have unchecked the Isolate script checkbox and also the field name is "request_item.requested_for" but still its not working for me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 03:33 AM
are you sure the field is from RITM and not REQ?
request_item.request.requested_for
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader