Help Needed: Notifications Not Triggering from Script Include in ServiceNow

DipinVasu
Tera Contributor

Hi Everyone,
I'm relatively new to ServiceNow and currently facing an issue with triggering notifications from a Script Include. I'm working on a feature where it's crucial to notify users about certain responses, even if they have navigated away from the original page or form. The idea is to ensure that users can refer back to these notifications at their convenience.

 

var AsyncStatusScriptInclude = Class.create();
AsyncStatusScriptInclude.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    callAsyncStatusOutboundCall: function() {
        try {
            var jsonBody = this.getParameter('jsonData');
            var resourceId = this.getParameter('id');
            
            var r = new sn_ws.RESTMessageV2('DEVICE', 'GetDeviceAsync');
            r.setRequestBody(jsonBody);
            r.setStringParameter('resourceId', resourceId);
            
            var response = r.execute();
            var responseBody = response.getBody();
            var httpStatus = response.getStatusCode();

            var result = {
                status: httpStatus,
                body: responseBody
            };
            // Example: Notify user based on the response status
            if (httpStatus === 200) {
                this.addNotification("Device status updated successfully");
            } else {
                this.addNotification("Failed to update device status");
            }

            return JSON.stringify(result);
        } catch (ex) {
            return JSON.stringify({
                status: "error",
                message: ex.message
            });
        }
    },
    
    addNotification: function(message) {
         gs.addInfoMessage(message);
    },
});