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

This helped me hahaha! Thank you!