Empty response from GlideAjax call to Script Include

Jason Williams
Kilo Sage

Hi All,

Hoping to shed some light on an issue that I've have come across with a Glide Ajax call returning an empty response.

I have a Service Portal widget within which I am trying to make a call to a script include. However, I was getting an 'Unhandled Exception' initially.

After adding some code to catch the error, I was presented with the following:

'Cannot read property 'documentElement' of undefined'.

So, I added console.log(response) within the callback function and can see that the object returned is of type basic and both the responseText & responseXML are 'undefined'.

find_real_file.png

I have mocked up a test widget and test script include following documentation and several other posts to see if it was an issue with our original widget, but I'm still getting the same result.

The thing that is really confusing matters is that if look at a widget which is in production and working fine within the widget editor, I also get a basic object returned, but if i use that same widget from the actual portal page it returns an XML as expected?!?

This is my widget:

function() {
	/* widget controller */
	var c = this;

	c.add = function() {

		try {
			var ga = new GlideAjax('testScriptInclude'); //This argument should be the exact name of the script include. 
			ga.addParam('sysparm_name', 'testFunction'); //sysparm_name is the name of the function in the script include to call.
			ga.getXML(myCallBack); //This is our callback function, which will process the response.

		}
		catch(e){
			console.log(e.message);
		}
	}

function myCallBack(response)
{
		console.log(response);
		try {
		var answer = response.responseXML.documentElement.getAttribute('answer');
		}
		catch(e){
			console.log(e.message);
		}
			
	}
}

This is the Script Include:

var testScriptInclude = Class.create();
testScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	testFunction: function(){

		var data = 'The script include has been reached';
		
		return data;

	},
	
	
    type: 'testScriptInclude'
	
	
});

Hoping someone can point me in the right direction.

Many Thanks,

Jason

1 ACCEPTED SOLUTION

vkachineni
Kilo Sage
Kilo Sage

GlideAjax is not supported in the Client Controller of a Widget in Service Portal

https://hi.service-now.com/kb_view.do?sysparm_article=KB0691908

 

 

//Can you try this way...may be you get lucky.

function() {
    /* widget controller */
    var c = this;

    c.add = function() {

        try {
            var ga = new GlideAjax('testScriptInclude'); //This argument should be the exact name of the script include. 
            ga.addParam('sysparm_name', 'testFunction'); //sysparm_name is the name of the function in the script include to call.
            //ga.getXML(myCallBack); //This is our callback function, which will process the response.
			
			
			ga.getXml(function(response) {
				if (!response)
				{
					console.log("No response");
					return;
				}
				else
				{
					console.log(response);
				}
			});		
			

        } catch (e) {
            console.log(e.message);
        }
    }    
}
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Jason,

is your script include client callable?

Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

Yes, I double checked this and it is definitely Client Callable.

Thanks,

Jason

vkachineni
Kilo Sage
Kilo Sage

GlideAjax is not supported in the Client Controller of a Widget in Service Portal

https://hi.service-now.com/kb_view.do?sysparm_article=KB0691908

 

 

//Can you try this way...may be you get lucky.

function() {
    /* widget controller */
    var c = this;

    c.add = function() {

        try {
            var ga = new GlideAjax('testScriptInclude'); //This argument should be the exact name of the script include. 
            ga.addParam('sysparm_name', 'testFunction'); //sysparm_name is the name of the function in the script include to call.
            //ga.getXML(myCallBack); //This is our callback function, which will process the response.
			
			
			ga.getXml(function(response) {
				if (!response)
				{
					console.log("No response");
					return;
				}
				else
				{
					console.log(response);
				}
			});		
			

        } catch (e) {
            console.log(e.message);
        }
    }    
}
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

Thanks for the link, that's strange as it does still appear to be working in a couple of widgets I've created which are running in production!?!

It's only when I run them in the widget editor that I get the issue.

Running them from the portal pages returns an XML object and works fine?!?

 

I tried your code, but unfortunately got an error stating 'ga.getXml is not a function', but thanks for the input.

Regards,

Jason