On change client script error

Community Alums
Not applicable

Hi All,

 

We are getting an error on state field 'onChange script error: TypeError: Cannot read properties of null (reading 'up') function onChange_change_request_state_14(control, oldValue, newValue, isLoading, isTemplate) { if (isLoading || newValue === '') { return; } if (newValue != "-5" || newValue != "-4") { $("impact_annotation").up().hide(); } else { $("impact_annotation").up().show(); } }'.

 

Below is the on change client script

 

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


    if (newValue != "-5" || newValue != "-4") {
        $("impact_annotation").up().hide();
    } else {
        $("impact_annotation").up().show();
    }

}


function showImpactAnnotation(bs) {
    if (bs.next()) {
        // Show annotation if high business criticality.
        if ((bs.busines_criticality == '1 - most critical') || (bs.busines_criticality == '2 - somewhat critical')) {
            // Hide the annotation
            $('my_annotation').up().show();
        }
        else {
            // Hide the annotation
            $('my_annotation').up().hide();
        }
    }
    else {
        // Hide the annotation
        $('my_annotation').up().hide();
    }
}
Can anyone please help me on how to get rid of that error. Thanks in advance
5 REPLIES 5

Hi @Community Alums ,

 

First you have to make your client script isolated "true".

RunjayPatel_0-1729762723960.png

 

change the code like below

 var element = document.getElementById('impact_annotation');         
if (!(newValue == "-5" || newValue == "-4")) {
      
        if (element) {            
            element.parentElement.style.display = 'none';
            }
       
    }else{
 if (element) {            
            element.parentElement.style.display = '';
            }

}

 

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

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
LinkedIn: https://www.linkedin.com/in/runjay
YouTube: https://www.youtube.com/@RunjayP

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