I am able to change the color by using OnChange client Script, Can someone help me with that?

Ashoka Panchal
Tera Contributor

I've 2 choices in the field, I am able to change the choice color by using OnChange client Script, But the background color disappearing, after saving the record. The background color should stay, after saving the record also for single choice, Please someone suggest me with that. Below is my code. 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}

var field = g_form.getValue('u_risk_type');
if (field == 'specialty_lines') {
var riskType = g_form.getControl('u_risk_type');
riskType.style.backgroundColor = "#A9E2F3";
} else {
if (field == 'complex') {
//control.style.backgroundColor = "white";
}
}

}

1 REPLY 1

AnubhavRitolia
Mega Sage
Mega Sage

Hi @Ashoka Panchal 

 

Please find the updated code below:

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (newValue === '') {
return;
}

var field = g_form.getValue('u_risk_type');
if (field == 'specialty_lines') {
var riskType = g_form.getControl('u_risk_type');
riskType.style.backgroundColor = "#A9E2F3";
} else {
if (field == 'complex') {
//control.style.backgroundColor = "white";
}
}
}

 

As this also need to be executed on loading so you just need to remove 'isLoading' from 2nd line so it can run while loading also.

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023