Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Change color on field label

Steve42
Tera Expert

I have the following script that I want to use to change the label color on a field that's calculated by a business rule. 

Anyway Here is the code:

var labelcolor = g_form.getLabel('u_crequests.u_risk_rla');
	if ('u_risk_rla' == '1') {
	labelcolor.style.color = 'green';
	} else if ('u_risk_rla' == '2') {
		labelcolor.style.color = 'yellow';
	} else {
		labelcolor.style.color = 'red';
	}

It does not seem to be working.  I think I have the information correct.
I have also tried these not being strings for the u_risk_rla values and that didn't work either

Basically if the value of the field is 1 the label will read low and I want the label to be green and so on down the list.

What am I doing wrong?

6 REPLIES 6

Mark Roethof
Tera Patron
Tera Patron

Hi there,

I assume you are using this code in a Client Script, on the Platform UI, is that correct?

If so, try:
(untested, I know this should work for Incident, though didn't test on custom table)

	var u_risk_rla = g_form.getValue('u_risk_rla');
	
	var labelcolor = document.getElementById('label.u_crequests.u_risk_rla');
	if(u_risk_rla == 1) {
		labelcolor.style.color = 'green';
	} else if(u_risk_rla == 2) {
		labelcolor.style.color = 'yellow';
	} else {
		labelcolor.style.color = 'red';
	}

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

I'll have to try it in a client script. I had it in with some other stuff but am going to break it out

Any luck with this? Or do we need to follow-up on this?

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

NO, it is not working for some reason,  I have tested it as a Client script/UI policy and nothing is working to change the color.  I can get it to sit as one color but not 3 based on the state of the RLA