Client callable script include is not working

prithviaram
Tera Contributor

Client Script Code - 

function onLoad() {
    // Initialize GlideAjax with the 'callerUtilsAjax' processor
    var ga = new GlideAjax("callerUtilsAjax");
    ga.addParam("sysparm_name", 'getName');
    ga.addParam("sysparm_caller", 'Prithvi Ramesh');
    ga.getXMLAnswer(function(response) {
        if (response) {
            alert(response);
        } else {
            alert("No response received from the server.");
        }

    });
}

 

Script Include - 

 

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

    // Method to get the caller's name and return a welcome message
    getName: function() {
        var name = this.getParameter('sysparm_caller'); // Retrieve the 'sysparm_caller' 
		gs.log("Welcome " + name + " !");
        return "Welcome " + name + " !"; // Return a welcome message
    },

    type: 'callerUtilsAjax' // Define the type of the processor
});
2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

Is the Script Include in the same scope as the Catalog Item / Client Script?  Is there a role required to access the script, defined on the Script Include related list?

Ankur Bawiskar
Tera Patron
Tera Patron

@prithviaram 

is the script include and client script in same scope?

Don't use gs.log() as it will break in scoped app

is the client callable checkbox marked as True?

are you testing with non-admin or admin?

if non-admin and it's not working then what role does that user have "snc_external"?

If yes then try adding this isPublic function in script include

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

    isPublic: function() {
        return true;
    },

    // Method to get the caller's name and return a welcome message
    getName: function() {
        var name = this.getParameter('sysparm_caller'); // Retrieve the 'sysparm_caller' 
        gs.info("Welcome " + name + " !");
        return "Welcome " + name + " !"; // Return a welcome message
    },

    type: 'callerUtilsAjax' // Define the type of the processor
});

If my response helped please mark it correct and close the thread so that it benefits future readers.

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