UI Action Workspace Client Script calling Script Include not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2024 02:39 AM
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:
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2024 02:52 AM
Hi Dear,
I have observed one syntax issue could you please try giving like below:
var ga = new GlideAjax (scriptincludename);
Thanks
Sony
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2024 03:18 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2024 08:42 AM - edited 07-03-2024 08:42 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2025 10:56 PM
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?