Unhandled exception in GlideAjax. Cannot read properties of null (reading 'responseXML')

StuPayne
Tera Contributor

Hello,

I am getting the error message above when I try to execute a script.

It is Client callable.

var GetInstanceInfo = Class.create();
GetInstanceInfo.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    initialize: function() {},

    getInstanceName: function() {
        var instanceName_s = gs.getProperty('instance_name');
        gs.info('Instance Name: ' + instanceName_s);
        return instanceName_s;
    },

    getInstanceURL: function() {
        var instanceURL_s = gs.getProperty('glide.servlet.uri');
        gs.info('Instance URL: ' + instanceURL_s);
        return instanceURL_s;
    },

    type: 'GetInstanceInfo',
    isPublic: true
});

 

function onLoad() {
    // Create my GetInstance Class
    var ga = new GlideAjax('GetInstanceInfo');
    ga.addParam('sysparm_name', 'getInstanceURL');
    ga.getXMLAnswer(function(response) {     
        g_form.setValue('current_instance', response.responseXML.documentElement.getAttribute("answer"));
    });
}
 
Any ideas why?
8 REPLIES 8

Toderean alexan
Tera Contributor

Hello @StuPayne,

 I want to highlight a few things when we work with client-server side calls. We usually have to pack the data when we send it to client side, for that is recommended to use "return new JSON().encode(instanceName_s);", this is for our case and when you load it to client side you need to unpack it from that "JSON" datatype, for this you can use "response.responseXML.documentElement.getAttribute("answer").evalJSON()".

 

var GetInstanceInfo = Class.create();
GetInstanceInfo.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    initialize: function() {},

    getInstanceName: function() {
        var instanceName_s = gs.getProperty('instance_name');
        gs.info('Instance Name: ' + instanceName_s);
        return instanceName_s;
    },

    getInstanceURL: function() {
        var instanceURL_s = gs.getProperty('glide.servlet.uri');
        gs.info('Instance URL: ' + instanceURL_s);
        return new JSON().encode(instanceURL_s);
    },

    type: 'GetInstanceInfo',
    isPublic: true
});
 

function onLoad() {
    // Create my GetInstance Class
    var ga = new GlideAjax('GetInstanceInfo');
    ga.addParam('sysparm_name', 'getInstanceURL');
    ga.getXMLAnswer(function(response) {     
        g_form.setValue('current_instance', response.responseXML.documentElement.getAttribute("answer").evalJSON());
    });
}

 

 

 

StuPayne
Tera Contributor

Both of these solutions worked kind of.  The value is being shown on the sreen.

@StuPayne 
Is the issue resolved?


If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.

StuPayne
Tera Contributor

I've tried everything suggested but not luck.  My manager told me that he has this same issue, and for me to move on.

 

Thank you all for your help.