Mystery of the colored read-only form field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2017 12:30 PM
I need to figure out how one of my form fields is getting its background color changed dynamically, while still being read-only.
On the Planned Task table, the Number field is read-only and changes to green after a condition is met.
There is a Style record setup:
and as far as i can tell that's the only thing that could be causing the color change. I've checked Client Scripts and UI Policy and can't find anything that appears to impact this.
That being said, I have another read-only field, Status, that I want to have change color based on its value. It works fine in the List View. It doesn't work at all on the form.
I have Style records setup for the available options, Green/Yellow/Red. I have a Client Script that works fine if the field is NOT read-only:
Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
/*if (isLoading || newValue == '') {
return;
}*/
// Variables
var tableName = g_form.getTableName();
var elementID = gel(tableName + ".status");
// Change the background color based on status field.
var ajax = new GlideAjax('ProjectStatusColorHelper');
ajax.addParam('sysparm_name', 'setStatusColor');
ajax.addParam('sysparm_value', newValue);
ajax.getXMLWait();
var color = ajax.getAnswer();
elementID.style.backgroundColor = color;
}
How can I get this to work when the field is read-only like Number?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2017 01:16 PM
Hate when I do this, but here's what I ended up doing to get around this issue. I haven't seen anyone else offer this solution up so...
- I took off the Read-Only flag on the Dictionary of 'Status'.
- Created a list_edit ACL which restricts who can modify Status from a list (essentially no one).
- Created a UI Policy that restricts Status to be read only when the form is viewed.
- Left my existing Client Script in place
Tada it works, while still basically keeping the Status field read-only in all places.
Glad I spent over an hour on this...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2017 01:39 PM
That feeling when you fixed your own issue . Glad that it worked .
Thanks,
Bharath.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-26-2017 10:18 PM
I've had a similar issue with Read-Only fields and Styles, found these 2 PRB's that acknowledge the issue/s but do not promise any fix:
PRB638178: Field styles on forms and lists do not behave as expected
https://hi.service-now.com/kb_view.do?sysparm_article=KB0584393
PRB638484: Value-based field styles applied to forms inconsistently on UI14 and UI15
https://hi.service-now.com/kb_view.do?sysparm_article=KB0564026