Change Background color of Number field to Yellow when attachment is attached by Requester
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
Hello All,
I got a requirement where the 'Number' field background color should get updated to yellow when attachment is attached by Requester.
Could you please help me with your inputs to achieve this scenario.
Thanks for looking into this.
Thanks,
Pujitha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6 hours ago
if this in native then this is possible with g_form.getControl() in onLoad client script + Display business rule
If in workspace then not possible
Sharing an example, but please enhance
Display BR:
(function executeRule(current, previous /*null on display*/ ) {
var requester = current.sys_created_by; // or your requester field
var attachmentGR = new GlideRecord('sys_attachment');
attachmentGR.addQuery('table_name', current.getTableName());
attachmentGR.addQuery('table_sys_id', current.sys_id);
attachmentGR.addQuery('sys_created_by', requester);
attachmentGR.setLimit(1);
attachmentGR.query();
g_scratchpad.hasRequesterAttachment = attachmentGR.hasNext();
})(current, previous);
onLoad client script:
function onLoad() {
if (g_scratchpad.hasRequesterAttachment) {
var numberControl = g_form.getControl('number');
if (numberControl) {
numberControl.style.backgroundColor = 'yellow'; // set back ground
numberControl.style.color = 'red'; // to set the color of field
}
}
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago - last edited 5 hours ago
If you'd like to set the field color in a list view, you can achieve this by creating a Field Style record in the sys_ui_style table.
-
For style field, you can use something like:
background-color: yellow; -
For the Value field, you can use a script such as:
javascript: new YourScriptInclude().yourFunction()
— where you define your logic based on the required condition.
Additionally, as @Ankur Bawiskar mentioned, you can use a Display Business Rule to populate g_scratchpad for the native view. This same g_scratchpad variable can be reused in your Field Style's Value field for the list field style.
Example:
In the Field Style record, set the Value field to:javascript:if(g_scratchpad.hasRequesterAttachment){ true; }
Stay awesome,
Roshnee Dash
