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

Chaitanya Redd5
Tera Guru

Hi Steve,

Could you please give a try with below piece of code in OnLoad Client Script and give a try once. I tried with below piece of code in my PDI and it's working.

Please make sure that the Isolated Script checkbox in client script is unchecked.

function onLoad() {
	//Type appropriate comment here, and begin script below
	var callerLabel = $('label.u_crequests.u_risk_rla');
	var risk = g_form.getValue('u_risk_rla');
	if (risk == '1') {
		callerLabel.setStyle({color: "green"});
		} else if (risk == '2') {
			callerLabel.setStyle({color: "yellow"});
			} else {
				callerLabel.setStyle({color: "red"});
				}
			}

 

Kindly mark my answer as Correct and Helpful based on the Impact.

Regards,

Chaitanya