How to change a field style color
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2024 04:39 PM
Hello everyone,
I'm working on incident table, and I want to change the service field font when the priority changes. Meaning, if the priority is critical, I want the service field font turn in red.
But my code is not working :

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2024 07:24 AM
Hello @Honor_ Lagaza -
I am not sure you can do this using a client script, as you should see the message within a new client script form, and your script would be effected:
Are you able to offer the use case as to why you are looking to change the field font color to red?
If you are looking to make the field mandatory, you could do so easily using a UI Policy. So that when Priority changes to Critical (1), Service field becomes mandatory with a red asterisk next to it.
Or if you are looking to call out the field even more, you could display a message box above/below it to call out it using a client script.
Not Critical:
When changed to critical:
onChange Client Script:
Script (Example):
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var priority = g_form.getValue('priority');
if (priority == '1') {
g_form.showFieldMsg('business_service', 'Priority is Critical!', 'error');
} else {
g_form.hideFieldMsg('business_service', 'error');
}
}
I am interested in understanding your Use Case to make the font red from the Service field.
If it is truly to just call it out more/make the person working on the Incident pay attention to the field. I would make it Mandatory using a UI Policy based on the Priority Field.
Or you could use the showfieldmsg option within a Client Script (onChange) based on the Priority Field.
Or even combine both. UI Policy to make the field mandatory AND display a message informing the person working the ticket.
I hope this helps you out -
Cheers,
-Rob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 02:22 AM
Did you try to set this up in the sys_ui_style table?
See this page for more information: Define field styles (servicenow.com)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 02:56 AM
Hi @Honor_ Lagaza check below code and screenshots i done on my pdi its working
if my answer help please mark helpful and accept solution