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

Abhinandan Pati
Giga Guru

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.

@Chuck Tomasi @denumchikin @Ankur Bawiskar @Göran Lundqvist @nathanfirth @Pradeep Sharma @Tim Woodruff 

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

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

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

Sidhant Pradhan
Kilo Contributor

Change your script include Accessible from field value from This application scope only to All application scopes.

 

lasse3
Mega Guru

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!

@Lasse I see that you said:  "Please note that the use of getXMLWait() is no longer supported."

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.