How to sent an email from the script ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 06:37 AM
Hi,
I have a problem, cause I'm trying to sent an email from the script and it is not working.
Look, I have a table and I have a group of users which have to create a record once per week.
based on this table record I want to sent a remind notification every friday to users which doesn't create a record yet.
I think it will be a good Idea to use "Schedule script Execution" module but probably my script skills are not as good for that.
That's what I've prepared:
function getUserAssigned() {
// var getUser = '';
var query = 'sys_created_onONThis week@javascript:gs.beginningOfThisWeek()@javascript:gs.endOfThisWeek()';
var grCheckuser = new GlideRecord('u_calendar_events');
grCheckuser.addEncoudedQuery(query);
grCheckuser.addEncoudedQuery(u_calendar_events.u_user, 'f4a92de9870cc610322ea9383cbb354e');
grCheckuser.query();
while(grCheckuser.next()){
gs.eventQueue('incident.inserted', current,"Test message", grCheckuser.u_user);
gs.info('TEST info ');
// gs.eventQueue('incident.inserted', gr, gr.u_user);
// gs.eventQueue('incident.inserted', gr, gs.getUserName(u_user.name()));
// gr.update();
}
}
do not focus on this script, I know I'do not have a specify a group and there is a wrong of condition.
How to fix this ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 11:17 PM
Hello @DIVI_IT,
Please refer to the below link:
https://www.servicenow.com/community/developer-forum/sending-an-email-from-within-a-script/m-p/20094...
Mark my correct and helpful, if it is helpful and please hit the thumbs-up button to mark it as the correct solution.
Thanks & Regards,
Abbas Shaik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 11:28 PM
Hi @DIVI_IT,
Make sure you have records when you apply the conditions in addQuery.
Try this updated scripts -
function getUserAssigned() {
// var getUser = '';
var query = 'sys_created_onONThis week@javascript:gs.beginningOfThisWeek()@javascript:gs.endOfThisWeek()';
var grCheckuser = new GlideRecord('u_calendar_events');
grCheckuser.addEncoudedQuery(query);
grCheckuser.addEncoudedQuery(u_calendar_events.u_user, 'f4a92de9870cc610322ea9383cbb354e');
grCheckuser.query();
gs.info('grCheckuser record count: ' + grCheckuser.getRowCount());
while (grCheckuser.next()) {
gs.eventQueue('incident.inserted', grCheckuser, "Test message", grCheckuser.u_user.toString());
gs.info('TEST info ');
// gs.eventQueue('incident.inserted', gr, gr.u_user);
// gs.eventQueue('incident.inserted', gr, gs.getUserName(u_user.name()));
// gr.update();
}
}
Thanks,
Sagar Pagar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 11:51 PM
Hi @DIVI_IT
please follow some threads for triggering notification some ways:-
https://tech.forums.softwareag.com/t/servicenow-email-notification/237436
https://tech.forums.softwareag.com/t/servicenow-email-notification-via-event/237437
Please mark reply as Helpful/Correct, if applicable. Thanks!