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

Rohit  Singh
Mega Sage

Hi @StuPayne ,

 

Can you replace your code and try. I hope you have a field with the name "current_instance" in the table where you are writing On Load Client Script. 

 

If it doesn't then see what value you are getting in  gs.info('Instance URL: ' + instanceURL_s); as part of troubleshooting.

 

 ga.getXMLAnswer(prop_result);
function prop_result(response)
{
 g_form.setValue("current_instance",response);
}

 

 

If my response helped, please hit the Thumb Icon and accept the solution so that it benefits future readers.

 

Regards,
Rohit

Hi @StuPayne 

 

Can you please mark the response as helpful and accept the solution. If applicable.

 

By this it will help other readers as well.

 

Regards,

Rohit 

Chaitanya ILCR
Kilo Patron

Hi @StuPayne ,

update your client script

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);
    });
}

 

getXMLAnswer parses the answer and shares it. we don't have to write this with getXMLAnswer

response.responseXML.documentElement.getAttribute("answer")
 
@

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

Medi C
Giga Sage

Hi @StuPayne 

Please use below onLoad script:

function onLoad() {
    var ga = new GlideAjax('GetInstanceInfo');
    ga.addParam('sysparm_name', "getInstanceURL");
    ga.getXML(processResponse);
}

function processResponse(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    if (answer) {
       g_form.setValue('current_instance', answer);
    }
}

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