Set font color in a script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2013 02:01 PM
I am displaying the Caller's phone number on the incident form and setting it to read-only through a script. The script displays the phone number field only if it contains a value, and uses setReadOnly() to set it to read-only. The problem I am having is that the read-only field is grayed out making it hard to read, and I would like to set the font color to black.
My first solution was to create a new Field Style and set the 'phone' field color to black. This works exactly how I want it to on Firefox, but when I open the form on Internet Explorer the field is still grayed out. When the form first loads it is black for a second, then grays itself out. (I believe the order must be different between Firefox and IE: Firefox reads the script first, sets the field to read-only, then reads the Field Style to set the color to black. IE reads the Field Style first, sets the color to black, then reads the script to set the field to read-only and grays it out.)
Is there a way to set the font color in a script so I can add this line of code after setting the field to read-only? I have only been able to find how to change the field label color, not the actual text inside the field. Any help here would be greatly appreciated.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2013 04:28 PM
I just tried it in demo014 and it works fine with the Field Style running in IE (although it is IE 11). Check it out there maybe (I'm showing the text in Red to make it real obvious, but Black was working as well). The demo versions are running Dublin now so I tried it in one of our instances still running Berlin and it is fine there as well.
I'm wondering if there is a script error somewhere that is actually causing the problem. Script errors, anywhere, will prevent all other Client Scripts, UI Policies, etc... from running once an error happens, so it does not have to be the script that is setting it read-only. Take a look at the following post which explains how to view script errors - http://community.servicenow.com/blog/jimcoyne/internet-explorer-really-can-be-your-friend
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-22-2013 07:19 AM
I am running Calgary on IE 9 and no script errors are showing up. When you tested this, did you make the field read-only?
I tested this scenario on multiple instances and I'm having the same problem throughout. Attached are two screenshots of IE and Firefox, where the priority field is set to yellow. When the incident form loads in IE, it is initially set to yellow for a split second then switches to being grayed out. It is working properly on Firefox, where the field is yellow and still read-only. Any other ideas on how I can debug this?
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-22-2013 07:36 AM
If I create the Field Style on a field that isn't read-only, it works correctly in IE. It is only when the field is read-only when it doesn't work in IE.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-22-2013 08:03 AM
Try adding this chunk of code to your client script after you set the field to read-only:
try {
$("incident.caller_id.phone").style.color = "red";
} catch(err) {}