Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

How to add javascript to value field?

Jared Wason
Tera Guru

Hi,

I am trying to set the background of a field to blue if the user has more than 1 PC assigned to them. I believe my script include is setup properly since it worked when running it in Background-Script, I think I just need to adjust "if(javascript:countAssignedTo(current.u_itd_customer))>1;". Anyone know how I need to adjust this?

 

find_real_file.png

find_real_file.png

1 ACCEPTED SOLUTION

kindly have a look on below article. it has mentioned the details. 

 

https://www.servicenowelite.com/blog/2013/11/24/custom-field-styles

View solution in original post

8 REPLIES 8

Ah that was my issue. I was testing this on a form, not in a list view. I want the style to apply specifically on the form. Is there a way to have the style appear on the form without blanking value?

kindly have a look on below article. it has mentioned the details. 

 

https://www.servicenowelite.com/blog/2013/11/24/custom-field-styles

harun_isakovic
Mega Guru

I think you have to initialize the script include first, dont remember how I did it exactly but before you start scripting in that value field you have to do "javascript:"

So maybe try

javascript: new countAssignedTo(current.u_itd_customer)>1

Sudhanshu Talw1
Tera Guru

Hii

javascript: var answer = new countAssignedTo(current.u_itd_customer) >1; answer;

 

apply style in the style field.

 

 

Thanks

Sudhanshu