OnChange script error for Readonly color coded field

Abdul Rashid
Tera Contributor

Hi, 

On the audit Engagement record, for result field to set the colour code I have written OnChange Client Script. The Color code is set as per selected dropdown options. But the issue is when the result field becomes readonly it showing the following onChange script error, as shown in figure. I have written the following OnChange Client Script, please help me over this. Thank you.

-------------------------------------------------------------------------------------------------

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

    if (newValue === '') {
       control.style = 'background-color: '; //to make the field colour less even for 'None'
        return;
    }

     var eleId = g_form.getElement("result");
    switch (newValue) {
        case "inadequate":
            eleId.setStyle({
                backgroundColor: "red"
            });
            break;
        case "improvement":
            eleId.setStyle({
                backgroundColor: "#FFBF00"
            });
            break;
        case "generally_sat":
            eleId.setStyle({
                backgroundColor: "yellow"
            });
            break;
        case "satisfactory":
            eleId.setStyle({
                backgroundColor: "green"
            });
            break;

        default:
            eleId.style.backgroundColor = " ";
            break;
    }
//to make the dropdown not to display the colours.
    g_form.getOption("result", "").style.backgroundColor = "white";
    g_form.getOption("result", "inadequate").style.backgroundColor = "white";
    g_form.getOption("result", "improvement").style.backgroundColor = "white";
    g_form.getOption("result", "generally_sat").style.backgroundColor = "white";
    g_form.getOption("result", "satisfactory").style.backgroundColor = "white";

}

 

 

AbdulRashid_0-1708256868204.pngAbdulRashid_1-1708256884682.png

 

1 REPLY 1

Community Alums
Not applicable

Hi @Abdul Rashid ,

Please check for any client script OOTB which makes the all the fields, read-only, that's not allowing your script to work while read-only.