How to change font color in field but not list view?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2022 10:39 AM
Hey all,
I'm hoping for some help. We are currently using a Field Style to change the Number field on Incident to a blue background with a white font.
With that being said, if, in List View, you move the column for the Number field to a column other than the first column, the white font disappears on the white background.
Is there any way to keep the font and background color changes for the field itself on the form, but make the font black in List View only?
Thanks!
Mat G.
- Labels:
-
User Interface (UI)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2022 10:47 AM
To make the UI Style apply only to form, I suggest go with Onload client script.
var numberField = $('incident.number');
numberField.setStyle({color: "white",backgroundColor: "skyblue"});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2022 06:20 AM
Thank you. I will try that out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2022 06:29 AM
for form you need to use script combination of Display BR + onLoad client Script
DOM manipulation is not required.
1) Display business rule on incident table
(function executeRule(current, previous /*null when async*/) {
// Add your code here
g_scratchpad.updatedBy = current.sys_updated_by;
g_scratchpad.assignedToUser = current.assigned_to.user_name;
})(current, previous);
2) on Load client script
function onLoad(){
var control = g_form.getControl('number');
if(g_scratchpad.updatedBy == g_scratchpad.assignedToUser){
control.style.color = 'white'; // to set the color of field
control.style.backgroundColor = "blue"; // to set the background color
}
else{
control.style.color = ''; // to clear the color of field
control.style.backgroundColor = ""; // to clear the background color
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2022 07:45 AM
Ankur,
Thank you for the information. I did try both scripts and removed the Field Styles script and I could not get it to work. I'm not sure why or if I am missing something.