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

the .getXMLWait() call in the client script is not supported by ServiceNow. Not that it's not supported for workspace client scripts, the call itself can't be used in any client script. I think it's still works, but ServiceNow doesn't support it anymore. It's a synchronous call --- you are telling the browser to lock the thread on your machine to hold until you get the message back, and that can be an issue. They have replaced it with .getXML which is an asynchronous call with a timeout, which is a better practice.