Cannot call script include from client script

Francis
Mega Expert

Hi fellow service-now developers,

I am trying to call a "Script Include" from a "Client script", but I cannot make it works.

Client script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    var ga = new GlideAjax('VdlAddressUtils');
    ga.addParam('sysparm_name', 'hasIdGDA');
    ga.getXML(getResponse);

    function getResponse(response) {
        var res = response.responseXML.documentElement.getAttribute("answer");
        alert(res)
    }
}

 

Script include:

var VdlAddressUtils = Class.create();
VdlAddressUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    hasIdGDA: function() {
        return "1";
    },
    type: 'VdlAddressUtils'
});

Do you know why?

 

PS: My script include is accessible remotely.

PS2: My alert shows a "Null".

 

Edit: After the suggestion of @Aman Kumar, I added a gs.info into my script include and I did get a log.

1 ACCEPTED SOLUTION

Francis
Mega Expert

Ok, got it guys.

I had a "gs.log("!!!HERE!!");" into my script include, and that causes my issue.

 

Thank you all!

View solution in original post

11 REPLIES 11

Hello! Thank for the suggestion. I did add the "gs.info" into my script include. I can confirme that it is getting called.

 

My only issue is the alert shows a "null".

 

I also added the semi-colon.

Feel free to mark helpful, if it assisted you

Thanks!

Best Regards
Aman Kumar

Ankur Bawiskar
Tera Patron

Hi,

try to use this syntax

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '') {
		return;
	}

	var ga = new GlideAjax('VdlAddressUtils');
	ga.addParam('sysparm_name', 'hasIdGDA');
	ga.getXMLAnswer(function(answer){
		alert(answer);
	});
}

Regards
Ankur

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

Hello! Thanks for the answer, but now my alert now shows: "[object XMLHttpRequest]"

Mahesh23
Mega Sage

Hi,

Seems like code is correct

Tested in PDI

find_real_file.png