Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to trigger an event from script include on submit of a catalog client script

Hari1
Mega Sage

Hi,

I need to trigger an event on Submit of a catalog client script. I am using Script Include to trigger an event. I need to send notification to the target record of the submitted catalog request.

Catalog Client Script: On Submit

var sysIdRitm = g_form.getUniqueValue();

var ajx = new GlideAjax('updateRemoveUsersDevices');
ajx.addParam('sysparm_status', status);
ajx.addParam('sysparm_sysId', sysIdRitm);
ajx.getXML(updateValues);

        function updateValues(response) {
            var answer = response.responseXML.documentElement.getAttribute("answer");
        }

Script Include:

var sysId = this.getParameter('sysparm_sysId');

var ritmSysId = new GlideRecord('sc_req_item');
ritmSysId.getValue(sysId);
             
gs.info("Script Include - ritmSysId:" + ritmSysId);
                    
gs.eventQueue('usr_updated',ritmSysId,test,'');

 

I am using the above code by the mails are not being triggered.
    

9 REPLIES 9

Sagar Pagar
Tera Patron

Hi,

Try this updated scripts-

/* Catalog Client Script: On Submit */

var sysIdRitm = g_form.getUniqueValue();

var ajx = new GlideAjax('updateRemoveUsersDevices');
ajx.addParam('sysparm_status', "status");
ajx.addParam('sysparm_sysId', sysIdRitm);
ajx.getXML(updateValues);
    function updateValues(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
    }

/* Script Include: */

status: function (){
var sysId = this.getParameter('sysparm_sysId');

var ritmSysId = new GlideRecord('sc_req_item');
ritmSysId.getValue(sysId);
            
gs.info("Script Include - ritmSysId:" + ritmSysId);
                
gs.eventQueue('usr_updated',ritmSysId, ritmSysId.opened_by); // check field name for submitted by
}

 

Thanks,

Sagar Pagar

The world works with ServiceNow

Hi,

I still don't see the notifications triggered.

Below is the logs.
find_real_file.png

If i use JSON.stringify() and log them then i see the below.
find_real_file.png

above is almost there, but in the SI, it needs to get the record from the table as an object to pass into gs.eventQueue:

var ritmObj = new GlideRecord('sc_req_item');

ritmObj.get(sysId);
var ritmOpenedBy = ritmObj.getValue('opened_by');

gs.eventQueue('usr_updated', ritmObj, ritmOpenedBy);

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Why to trigger email using onSubmit catalog client script?

regards
Ankur

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