
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2025 01:23 AM
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:
Notification:
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 ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2025 11:03 PM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2025 02:13 AM
hello @Deepika Mishra
The format for gs.eventQueue() is this -
I don't think "Eail sent succesfully and null was required ? No record is passed.
Please verify this.
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY QQ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2025 02:15 AM
this link has similar requirement, please check and enhance/fix your widget code
Email notification at the click of a button in Service Portal
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2025 02:27 AM
where is this widget used? share some more details about it along with screenshots
how are you determining email should be triggered foe which INC?
I believe in eventQueue() since you are not passing GlideRecord object as 2nd parameter it's not knowing which RECORD to use to trigger
Try to use this and see if it goes to server side
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() {
data.success = false;
if (input && input.action === 'triggerEmail') {
gs.addInfoMessage('server script called');
// you should query incident table with sysId and then use the GlideRecord object here
gs.eventQueue('trigger_email_event', obj, gs.getUserID(), 'Email sent successfully');
data.success = true;
}
})();
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2025 10:34 PM
I added below, still facing issue
HTML:
<h2>Button triggering notification</h2>
<div>
<button class="btn btn-primary" ng-click="c.sendEmail()">Send Email</button>
</div>
Server:
(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()) {
obj = inc.sys_id;
gs.info('2. DeeT Incident Number: ' + inc.number + ' with sys_id: ' + obj);
}
gs.eventQueue('trigger_email_event', obj, 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;
})();
Client:
api.controller = function($http) {
var c = this;
c.sendEmail = function() {
console.log('sendEmail function called');
c.server.get({
action: 'triggerEmail'
}).then(function(response) {
console.log('Server response:', response);
if (response.data.success) {
alert('Email sent successfully');
} else {
alert('Failed to send email');
}
});
};
};
Log Results:
Guide me what to change in this ?