Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Change Background color of Number field to Yellow when attachment is attached by Requester

pujitha K
Tera Contributor

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

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@pujitha K 

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! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Roshnee Dash
Tera Guru
Tera Guru

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; }

 

Your feedback makes the community stronger! If you found this helpful, marking it as the correct answer helps others.
Stay awesome,
Roshnee Dash