The CreatorCon Call for Content is officially open! Get started here.

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

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

Jason,

 

Typo. it should be upper case

 

ga.getXML

 

ga.getXML(function(response) {
				if (!response)
				{
					console.log("No response");
					return;
				}
				else
				{
					console.log(response);
				}
			});	
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

Tried that too, but back to the same basic object being returned!

I'll mark your original answer as correct as I have gone with the option from the HI article of calling the script include from the Server Script.

Thanks again.

Jason

SatheeshKumar
Kilo Sage

Guys,

this was known behaviour

check the below Article 

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

 

GlideAjax is supported in Client Scripts in Service Portal, but it is not currently supported in the Client Controller of a Widget. Script Include functions are only accessible in the Server Script of the widget.

 

-Satheesh