background color of field not working in client script

sunil7
Giga Expert

Hi everyone , I want to change the background color of field Resudual Risk(u_priority) string field with choices , Writing one onload client script but not working please see below

 

Code : onload client script 

code is going inside if and getting alert but background color is not changing

var element = g_form.getElement('u_priority');
   // alert(element);
    var accessType = g_form.getValue('u_priority');
    if (accessType == 'Low') {
   alert(accessType);
        element.style.backgroundColor = "LimeGreen";
    }
    if (accessType == 'Medium') {
  alert(accessType);
        element.style.backgroundColor = "yellow";
    }
    if (accessType == 'High') {
	alert(accessType);
        element.style.backgroundColor = "orange";
    }
    if (accessType == 'Well Controlled') {
  alert(accessType);
        element.style.backgroundColor = "green";
    }
    if (accessType == 'Critical') {
  alert(accessType);
        element.style.backgroundColor = "red";
    }

10 REPLIES 10

Hi @rushabhgupta,

 

Hope you have gone through my above comments. Let me know if have any issues.

 

If my response helps you resolve your issue. Kindly mark it as helpful & correct. It will be helpful to future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow