- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2022 02:12 AM
how to make Requested for to red text and VIP badge if a user is VIP in sc_task table
The label of requested for is below
I take the reference of OOTB script of incident but that not worked for me
function onChange(control, oldValue, newValue, isLoading) {
var callerLabel = $('label.sc_task.requested_for');
var callerField = $('sys_display.sc_task.requested_for');
if (!callerLabel || !callerField)
return;
if (!newValue) {
callerLabel.setStyle({
backgroundImage: ""
});
callerField.setStyle({
color: ""
});
return;
}
g_form.getReference('request_item.request.requested_for', vipCallerCallback);
}
function vipCallerCallback(caller) {
var callerLabel = $('label.sc_task.requested_for').down('label');
var callerField = $('sys_display.sc_task.requested_for');
if (!callerLabel || !callerField)
return;
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: ""
});
}
}
Solved! Go to Solution.
- Labels:
-
Multiple Versions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2022 08:09 AM
function onLoad() {
var reqfor = g_form.getReference('request_item.requested_for');
var reqforLabel = document.getElementsByClassName('col-xs-12 col-md-3 col-lg-4 control-label')[1];
var reqforField = document.getElementById('sys_display.sc_task.request_item.requested_for');
if (reqfor.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 = '';
}
}
This work for me finally
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2022 04:37 AM
Hi
You can follow the Client Script example which is present OOTB.
Link: https://<instance_name>.service-now.com/sys_script_client.do?sys_id=8f0b3ee00a0a0b5700e75f4aaabe4953
You can add the code to modify the text color of the field.
Remark: Make sure the field Isolate Script is set to false
Please mark my answer as correct if this solves your issues!
If it helped you in any way then please mark helpful!
Thanks and regards,
Kartik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2022 05:44 AM
i already did that but non worked
function onChange(control, oldValue, newValue, isLoading) {
var callerLabel = $('label.sc_task.requested_for');
var callerField = $('sys_display.sc_task.requested_for');
if (!callerLabel || !callerField)
return;
if (!newValue) {
callerLabel.setStyle({
backgroundImage: ""
});
callerField.setStyle({
color: ""
});
return;
}
g_form.getReference('request_item.request.requested_for', vipCallerCallback);
}
function vipCallerCallback(caller) {
var callerLabel = $('label.sc_task.requested_for').down('label');
var callerField = $('sys_display.sc_task.requested_for');
if (!callerLabel || !callerField)
return;
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
07-31-2022 05:15 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2022 08:09 AM
function onLoad() {
var reqfor = g_form.getReference('request_item.requested_for');
var reqforLabel = document.getElementsByClassName('col-xs-12 col-md-3 col-lg-4 control-label')[1];
var reqforField = document.getElementById('sys_display.sc_task.request_item.requested_for');
if (reqfor.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 = '';
}
}
This work for me finally