Mystery of the colored read-only form field

Shane J
Tera Guru

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.

find_real_file.png

There is a Style record setup:

find_real_file.png

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.

find_real_file.png

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:

find_real_file.png

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?

3 REPLIES 3

Shane J
Tera Guru

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...



  1. I took off the Read-Only flag on the Dictionary of 'Status'.
  2. Created a list_edit ACL which restricts who can modify Status from a list (essentially no one).
  3. Created a UI Policy that restricts Status to be read only when the form is viewed.
  4. 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...


That feeling when you fixed your own issue . Glad that it worked .



Thanks,


Bharath.


Dale Hynes
Kilo Sage

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