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-25-2013 07:41 AM
This is for the Business phone field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-25-2013 07:38 AM
When I use $("sys_readonly.incident.caller_id.phone").style.color = "red"; I get the following script error:
Error: Unable to get value of the property 'style': object is null or undefined
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-25-2013 12:46 PM
How you make the field read-only can affect the way the element is named by ServiceNow. Use firebug (or view the source) to inspect the element to determine it's actual element name.
On the demo instance, I added the business number (caller_id.phone) to the incident form, and then made it read-only using a UI policy. In this case, it's element name is "incident.caller_id.phone".
If this helped, please mark your question as answered. Thanks!