Can we make a Glide Ajax call in Workspace Client Script?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2020 08:09 AM
Hello Everyone,
I am trying to update one of the table record in the UI Action of Customer Service Management application. It's working as expected in the native/default UI of ServiceNow and I am performing both client side and server side operations in that UI Action.
To make it work in Agent Workspace I am making use of 'Workspace Client Script' field present on the UI action form.I am able to perform client side and server side operations using GlideRecord with a call back function using below code snippet
UI Action: Workspace Client Script
function onClick(g_form) {
if (g_form.getValue("work_notes") == "") {
g_form.setMandatory("work_notes", true);
alert("Please provide rejection notes.");
return false; //Abort submission
}
var crspdnc = new GlideRecord('sn_customerservice_correspondence_v1');
crspdnc.addQuery('sys_id', g_form.getUniqueValue().toString());
crspdnc.query(function(crspdnc) {
if (crspdnc.next()) {
g_form.setValue('approval', 'rejected');
g_form.save();
}
});
}
Now instead of using GlideRecord with a call back function I would like to make a GlideAjax call to update the record, but for some reason the control is not going inside Script Include and I am unable to perform server side operation in Script Include. Here is the code snippet that I tried
UI Action: Workspace Client Script:
function onClick(g_form) {
if (g_form.getValue("work_notes") == "") {
g_form.setMandatory("work_notes", true);
alert("Please provide rejection notes.");
return false; //Abort submission
}
var ga = new GlideAjax('sn_customerservice.CSMAgentWorkspaceUtil'); //Call script include to escape text
ga.addParam('sysparm_name', 'setApprovalState');
ga.addParam('sysparm_correspondence', g_form.getUniqueValue());
ga.getXML();
}
Script Include:CSMAgentWorkspaceUtil
var CSMAgentWorkspaceUtil = Class.create();
CSMAgentWorkspaceUtil.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
setApprovalState: function() {
gs.info('AP:Inside SI Correspondence: ');
var sysId = this.getParameter('sysparm_correspondence');
var crspdnc = new GlideRecord('sn_customerservice_correspondence_v1');
crspdnc.get(sysId.toString());
gs.info('AP:Correspondence: ' + crspdnc.number);
crspdnc.approval = "rejected";
crspdnc.assignment_group = crspdnc.parent.assignment_group;
crspdnc.assigned_to = crspdnc.parent.assigned_to;
crspdnc.update();
},
type: 'CSMAgentWorkspaceUtil'
});
Please correct me if I am missing something here.
- 5,957 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2020 09:30 AM
Hi Abhinandan,
I haven't got a chance to work on this part. but can you check the scope is same for the UI action and the script include; also script include is accessible from all scope if scope is different from UI action
Also please check some out of the box UI actions which have GlideAjax used in it:
https://instanceName.service-now.com/sys_ui_action_list.do?sysparm_query=client_script_v2LIKEGlideAjax&sysparm_view=
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2020 05:15 AM
Change your script include Accessible from field value from This application scope only to All application scopes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2020 03:11 AM
I know that this post is somewhat old, but just in case anybody else is struggeling with this.
What is missing from the Workspace Clients Script in this topis is a callback function on the getXML().
Here is example from the docs:
var ga = new GlideAjax('HelloWorld');
ga.addParam('sysparm_name', 'helloWorld');
ga.addParam('sysparm_user_name', "Bob");
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer); }
Please note that the use of getXMLWait() is no longer supported.
Other than that always check that the both the UI Action is has client marked as true and that the Script Includes is marked as "Client callable".
I hope this helps!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2022 10:50 AM
Can you please explain how you know that, and include a link, ideally?
And when you say "No longer supported" you mean Not Supported for "Workspace Client Scripts" correct? (Because I believe it is working fine in regular old client scripts.) Thanks.