Field Style in reference field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I would like a paperclip icon to be displayed in the request_item field of the sc_task table when a file is attached to the record set in the Request item.
To meet this requirement, I set the Filed Style as shown below.
However, while the icon appears in the list view, it does not appear on the form.
How can I apply this style to the form view?
Thank you in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi @MiY,
that's correct behaviour, the Field styles appear in list view only, for the form fields you need to write an onLoad client script.
I have this field with background set according to the values:
This is not reflected in list view, form only. So for the list view you will keep the field sytle and for the form field you will need onLoad client script...
And it was done by the following CS, you can take it as inspiration for your clip icon:
function onLoad() {
setTimeout(function() {
var fieldName = 'mood_score_tw';
var mstw = g_form.getValue(fieldName);
var control = g_form.getControl(fieldName);
control.style.color = 'black';
control.style.fontWeight = 'bold';
var bgColor = '';
if (mstw === 'Green') {
bgColor = '#b6fcb6';
} else if (mstw === 'Yellow') {
bgColor = '#fff9b1';
} else if (mstw === 'Red') {
bgColor = '#fcb6b6';
}
control.style.backgroundColor = bgColor;
if (control.parentNode) {
control.parentNode.style.backgroundColor = bgColor;
}
}, 300);
}
EDIT: the screenshot replaced with a better one.
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Thank you, so it's normal for it to only be applied to list views.
However, there are cases where it is applied to fields as well, as shown below.
Why is that? I haven't created a client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
yes sometimes it shows and the behavior is inconsistent and is intermittent.
ServiceNow doesn't intend to fix this.
this KB talks about the same and you can create your own client script to show it always based on your logic.
Value-based field styles applied to forms inconsistently on UI14 and UI15
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader