How do I change the field background colour?

ChuanYanF
Tera Guru

Dear experts,

 

I would like to know how do I configure the background label colour for a field to be like this?

ChuanYanF_0-1755487568915.png

Currently my script is like this but it does not show the color like the background I wanted above. How do i change my script so that my field whole background becomes red or green instead of gray now.

ChuanYanF_1-1755488033033.png

 

2 ACCEPTED SOLUTIONS

@ChuanYanF 

 

I do not think issue is with style or client script. Check your business rule where you set field value of 'u_final_scoring' or create a manual record and set the value of the field to 1 or 2 and test it.

 

Below is for reference where I simulated your use-case in my PDI,

Bhuvan_0-1755660392281.pngBhuvan_1-1755660406682.png

Bhuvan_4-1755660707083.png

Bhuvan_2-1755660423341.pngBhuvan_3-1755660433376.png

I hope you appreciate the efforts to mimic this scenario in my PDI and provide you with this  information by marking the posts helpful and accept the solution.

 

Thanks,

Bhuvan

View solution in original post

@ChuanYanF 

 

Glad to know it is working now. I can see there is a known issue in applying field styles for read-only fields and problem record is PRB663205. Not sure if enhancement request for this feature is made available,

 

https://www.servicenow.com/community/servicenow-ai-platform-forum/feature-request-apply-styles-to-re...

 

I have seem some community solutions but not sure if it would work and would recommend to uncheck 'Read Only' from dictionary and if you want to enforce it, do so from UI Policy.

 

See below for sample UI policy, change filter conditions to suit your requirement

Bhuvan_0-1755679096101.png

'u_final_scoring' field is read-only and styles would work with this option,

Bhuvan_1-1755679175837.png

I hope you appreciate the efforts in providing this solution and would mark the post helpful and accept the solution.

 

Thanks,

Bhuvan

View solution in original post

24 REPLIES 24

@ChuanYanF 

 

I do not think issue is with style or client script. Check your business rule where you set field value of 'u_final_scoring' or create a manual record and set the value of the field to 1 or 2 and test it.

 

Below is for reference where I simulated your use-case in my PDI,

Bhuvan_0-1755660392281.pngBhuvan_1-1755660406682.png

Bhuvan_4-1755660707083.png

Bhuvan_2-1755660423341.pngBhuvan_3-1755660433376.png

I hope you appreciate the efforts to mimic this scenario in my PDI and provide you with this  information by marking the posts helpful and accept the solution.

 

Thanks,

Bhuvan

Hi Bhuvan,

 

Thanks I see what is the problem now, because I want the field to be read-only thats why it overwrites the color which is grey. I disable read-only and now the color is visible. So how do I prevent that, if I still want the field to be read-only?

@ChuanYanF 

 

Glad to know it is working now. I can see there is a known issue in applying field styles for read-only fields and problem record is PRB663205. Not sure if enhancement request for this feature is made available,

 

https://www.servicenow.com/community/servicenow-ai-platform-forum/feature-request-apply-styles-to-re...

 

I have seem some community solutions but not sure if it would work and would recommend to uncheck 'Read Only' from dictionary and if you want to enforce it, do so from UI Policy.

 

See below for sample UI policy, change filter conditions to suit your requirement

Bhuvan_0-1755679096101.png

'u_final_scoring' field is read-only and styles would work with this option,

Bhuvan_1-1755679175837.png

I hope you appreciate the efforts in providing this solution and would mark the post helpful and accept the solution.

 

Thanks,

Bhuvan

Rafael Cardoso
Tera Guru
Tera Guru

If you want to change the field color in a custom field, you need to use the field styles (sys_ui_style table) or create a client script onLoad. In your example, the risk is using a client script.

RafaelCardoso_0-1755593225656.png

RafaelCardoso_1-1755593319700.png

 

Raf


Helpful post? Don’t forget to bookmark it, give it kudos, or mark it as the answer to help the community grow!

RaghavSh
Kilo Patron

In the sys_ui_style table, did you try setting "background-color: red;"  instead of color


Raghav
MVP 2023