Unhandled exception in GlideAjax. Cannot read properties of null (reading 'length') in stage Env

Kiran Maruthi
Tera Contributor

There is on change Catalog client script which will trigger when the request type field is changed. This client script will internally call script include.

While performing on change action ESC form I'm getting console error called (Only in STAGE environment)"Unhandled exception in GlideAjax. Cannot read properties of null (reading 'length')".

below this the client script:

function onChange(control, oldValue, newValue, isLoading) {
  if (isLoading) {
   
      return;
   }
   g_form.clearOptions("sub_request_e_c");
   

    var gaServiceGrpsAjax = new GlideAjax("SI Name");
    gaServiceGrpsAjax.addParam('sysparm_name', 'getSubRequest');
    gaServiceGrpsAjax.addParam('sysparm_requestType', newValue);
    gaServiceGrpsAjax.getXMLAnswer(function(answer) {
        var response = JSON.parse(answer);

        g_form.addOption('sub_request_e_c', '', '-- None --');
        for (var i = 0; i < response.length; i++) {
            g_form.addOption('sub_request_e_c', response[i], response[i]);
        }
        g_form.setValue('sub_request_e_c','');
    });

   //Type appropriate comment here, and begin script below
   
}
 
and here is the function in script include:
getSubRequest: function() {

        var requestType = this.getParameter("sysparm_requestType");
        var subRequests_list = [];
        var grSubRequest = new GlideRecord("table name");
        grSubRequest.addEncodedQuery('GOTOu_variable=sub_request_e_c^u_dependent_variable=request_type_e_c^u_active=true');
        grSubRequest.addQuery("u_dependent_variable_value", requestType);
        grSubRequest.orderBy("u_order");
        grSubRequest.query();
        while (grSubRequest.next()) {
            subRequests_list.push(grSubRequest.u_value.toString());
        }
        return JSON.stringify(subRequests_list);

    },
 
 
 
Pls note: this functionality is working as expected in DEV and TEST, but throwing the console error in STAGE after migration to stage.
 
pls suggest some solution to come out of this situation
 
2000102143_0-1718699539963.png

 

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

The error is caused by the Glide Ajax not returning a value.  Make sure the scope of the Script Include and ESC form are the same, or add the scope to the GA call.  Also check the ACL on the SI to make sure it is accessible in this environment. And of course make sure there is only one SI with this name.  You can add some gs.info or gs.addInfoMessage lines to the SI to confirm it is running, see the GR records found, etc. that should shed some light. 

View solution in original post

1 REPLY 1

Brad Bowman
Kilo Patron
Kilo Patron

The error is caused by the Glide Ajax not returning a value.  Make sure the scope of the Script Include and ESC form are the same, or add the scope to the GA call.  Also check the ACL on the SI to make sure it is accessible in this environment. And of course make sure there is only one SI with this name.  You can add some gs.info or gs.addInfoMessage lines to the SI to confirm it is running, see the GR records found, etc. that should shed some light.