Trigger an email notification based on a value change
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2022 04:07 PM
Hi,
I have a table in which the Fulfiller changes the Status to "Yes" by default the value is "No". The change can be done for multiple records, the thing is that we don't want to send a separate email for each record as it can be a bunch of emails.
I think that can be achieve using Scheduled Job Script, but we have records linked with an SCTASK number, so we want to send the email notification for those records associated to each SCTASK, for example we have two records linked with the SCTASK0080343 and we want to send an email that contains only these two records, then we have another two records linked to SCTASK0080428 so that would be another email notification containing those records.
So, basically the system should send two separate email notifications with their records.
I hope this makes sense
Any ideas? I have not started created the script.
Regards,
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2022 04:13 PM
Hello,
You may need to create another field that captures if the email has been sent or not (just to make things easier).
So, yes, you can create a scheduled job or flow that runs every 'x' minutes/hours/days and then checks for records on this table where ready for UDI = yes and the email sent field is no, then furthermore, groups (using the groupby method in GlideAggregate for example) and then fires an event, which triggers the notification, and then the near the last line of the script, you set that field value to true for the record(s) indicating that the email has been sent via the event being called.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2022 04:53 PM
Hi Allen, thanks for your reply.
I have never used GlideAggregate I don't have much experience in scripting. I tried with this but obviously it does work
Do you have any ideas?
var udi_gr = new GlideRecord('u_udi_tracking_data');
var gr = new GlideRecord('sc_task');
//gr.addQuery('state', 'Open'); //Check if the state is open
udi_gr.addEncodedQuery('u_status=Yes^u_complete_status!=Complete');
udi_gr.addQuery('udi_gr.u_task', 'gr.getUniqueValue()');
udi_gr.query();
while(udi_gr.next()) {
gs.eventQueue('UDI.EmailSME', udi_gr); //It will fire the event
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2022 06:25 PM
Duplicate posts:
- https://community.servicenow.com/community?id=community_question&sys_id=092708f0db40d5942dc24f781396...
- https://community.servicenow.com/community?id=community_question&sys_id=3808374edba74dd0770be6be1396...
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!