UI Action Workspace Client Script calling Script Include not working

Ruihster
Tera Contributor

Good Day,

 

I'm trying to call a Script Include using GlideAjax from the Workspace Client Script in an UI Action.

 

I need a Script Include since the UI Action requires to get data from a Table via GlideRecord which does not work with Client Scripts.

But now I have a problem: GlideAjax is not working as expected.

 

I've created a Test Script Include and a Test UI Action; the Test Script Include should return a String, but the UI Action does not even go to the Callback function.

 

The UI Action Workspace Client Script looks like this:

function onClick(g_form) {
	g_form.addInfoMessage("Button Pressed");
	var ga = GlideAjax('global.TestScriptInclude');
	ga.addParam('sysparm_name', 'getScriptMessage');
	ga.getXMLAnswer(parseResponse);

	function parseResponse(response) {
		g_form.addInfoMessage("GlideAjax Worked");
    }
}

The UI Action should print the first Message to check the button it self works, then perform the GlideAjax, but it never goes to the "parse Response" function.

 

The Script Include looks like this:

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

	getScriptMessage: function() {
		return "Message from Script Include";
	},

    type: 'TestScriptInclude'
});

and is Configured as following:

Ruihster_0-1719221249005.png

 

The UI Action is set to Client and List v2 and v3 Compatible.

 

Also when pressing the UI Action there is an Error in the Console:

SCRIPT:EXEC Error while running Client Script "GlideScopedScript": TypeError: Cannot read properties of undefined (reading 'initialize')

 The Error only occurs when calling the Script Include "var ga = GlideAjax('global.TestScriptInclude');"

 

I already looked in other UI Actions created by Servicenow which use Script Includes / GlideAjax and it looks the same but there it works.

 

I hope someone sees what's wrong or had the same experience and a solution maybe I configured something wrong.

 

Thanks

Regards.

5 REPLIES 5

Pullela Sony1
Tera Contributor

Hi Dear,

 

I have observed one syntax issue could you please try giving like below:

var ga = new GlideAjax (scriptincludename);

 

Thanks

Sony

Community Alums
Not applicable

Hi @Ruihster ,

Please try below code 

function onClick(g_form) {
	g_form.addInfoMessage("Button Pressed");
	var ga = GlideAjax('TestScriptInclude'); // Remove global from name of Script include
	ga.addParam('sysparm_name', 'getScriptMessage');
	ga.getXMLAnswer(parseResponse);

	function parseResponse(response) {
		g_form.addInfoMessage("GlideAjax Worked");
    }
}

And make sure that your Script Include is client callable 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak

Hey, Thanks for your Answer.
Removing the global from the name resulted in a Console Error, it was a 404 error that indicates that the Script Include wasn't found with that name. Adding the Global back removed the Error but still didn't get the Response from the Script Include.

I was able to fix the problem: I deleted the Script Include and created a new one from Scratch with the same Name, Application and Script and after that it worked.
Maybe there was an error with the ACL of the Script Include.

Still thanks for your Answer

Hi there! I know this is an old thread, but would you be kind enough to share if you built an ACL for the Script Include you created? If you did, how does it look?