On clicking button on the portal notification should be triggered

Deepika Mishra
Mega Guru

Hi All,

Usecase: On clicking the button a notification should be triggered to caller of the incident.

For this I developed below, however it is not working
Event:

DeepikaMishra_0-1743668256320.png

 

Notification:

DeepikaMishra_1-1743668311866.png

DeepikaMishra_2-1743668336638.png

DeepikaMishra_3-1743668363409.png



Widget:

HTML:

<h2>Button triggering notification</h2>
<div>
  <button class="btn btn-primary" ng-click="c.sendEmail()">Send Email</button>
</div>

Client Controller:

api.controller = function($http) {
    var c = this;

    c.sendEmail = function() {
        c.server.get({
            action: 'triggerEmail'
        }).then(function(response) {
            if (response.data.success) {
                alert('Email sent successfully');
            } else {
                alert('Failed to send email');
            }
        });
    };
};

Server:

(function() {
  if (input && input.action === 'triggerEmail') {
    gs.eventQueue('trigger_email_event', null, gs.getUserID(), 'Email sent successfully');
    data.success = true;
  } else {
    data.success = false;
  }
  return data;
})();

 

I am not sure why it isn't working. Can someone help with correction and execution ?

1 ACCEPTED SOLUTION

@Deepika Mishra 

some corrections in server side

gs.eventQueue() should be within the IF and it should include inc object

Hope event parm1 contains Recipient=true in your notification

(function() {
    gs.log('1. DeeT Server script started');
    if (input && input.action === 'triggerEmail') {
        var obj;
        var inc = new GlideRecord('incident');
        inc.addQuery('sys_id', '57af7aec73d423002728660c4cf6a71c');
        inc.query();
        if (inc.next()) {
            gs.eventQueue('trigger_email_event', inc, gs.getUserID(), 'Email sent successfully');
            data.success = true;
            gs.log('3. DeeT Event triggered: true');
        }
    } else {
        data.success = false;
        gs.log('3. DeeT Event triggered: false');
    }
    gs.log('4. DeeT Server script completed');
    return data;
})();

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

5 REPLIES 5

@Deepika Mishra 

some corrections in server side

gs.eventQueue() should be within the IF and it should include inc object

Hope event parm1 contains Recipient=true in your notification

(function() {
    gs.log('1. DeeT Server script started');
    if (input && input.action === 'triggerEmail') {
        var obj;
        var inc = new GlideRecord('incident');
        inc.addQuery('sys_id', '57af7aec73d423002728660c4cf6a71c');
        inc.query();
        if (inc.next()) {
            gs.eventQueue('trigger_email_event', inc, gs.getUserID(), 'Email sent successfully');
            data.success = true;
            gs.log('3. DeeT Event triggered: true');
        }
    } else {
        data.success = false;
        gs.log('3. DeeT Event triggered: false');
    }
    gs.log('4. DeeT Server script completed');
    return data;
})();

If my response helped please mark it correct and close the thread so that it benefits future readers.

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