Notification to be sent only once for the same record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-02-2020 04:43 PM
Hi Guys,
I have setup a schedule job runs each day and filter all the changes passed the planned end date didnt get close off then trigger an event called change.pass.end.date then triggers the notification to the change owners. but the problem i have is that notification will get send everyday when the schedule runs, is there a way to send notification only once for one change record ? or is there a better way of doing this ?
script in the schedule job:
var gr = new GlideRecord('change_request');
gr.addEncodedQuery('active=true^end_date<javascript:gs.beginningOfToday()^stateIN-4,-2,-1,0');
gr.query();
while (gr.next()) {
gs.eventQueue(".change.pass.end.date", gr);
}
Thanks,
- Labels:
-
Change Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-02-2020 04:55 PM
You can create a hidden true/false field on the change request table. This field will be used to identify whether the notification already sent for the record or not. In the while loop you can set that fields value to true. In the encodedQuery you can add query to filter only those records where true/false field is false.
Custom Field
Field Label - Notified
Field Name - u_notified
Type - true/false
Script will be like this.
var gr = new GlideRecord('change_request');
// added u_notified=false to get only records where notification has not been send yet.
gr.addEncodedQuery('u_notified=false^active=true^end_date<javascript:gs.beginningOfToday()^stateIN-4,-2,-1,0');
gr.query();
while (gr.next()) {
gs.eventQueue(".change.pass.end.date", gr);
gr.setValue('u_notified', true); // updating value of u_notified to true as the notification is send for current change.
gr.update();
}
Let me know if it works and please be kind to mark my response as CORRECT & HELPFUL, if it answered your question.
Thanks & Regards,
Sharjeel
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-02-2020 05:07 PM
Hi Sharjeel,
Thats a good idea to start, let me explain what i did here, basically i have setup 3 different notification for changes pass certain xxx days.
7 days passed - notification to xxx
14 days passed - notification to xxx
30 days passed - notification to xxx
if i add that extra field, dose it mean i have to create 3 different fields of different days to it to look at?
Thanks,
Rex

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-02-2020 05:27 PM
Hi Rex Shi,
As you have three separate notifications then you can go with choice field with choices [7 days, 14 days, 30 days] rather than creating three true/false fields.
For 7 days notifications you will query records where field value is none and upon sending the notification value will change to 7 days.
For 14 days notification you will query records where value is 7 days and upon sending the notification value will change to 14 days.
For 30 days notification you will query records where value is 14 days and upon sending the notification value will change to 30 days.
Note - make sure to make this field readonly so that other cannot change the value manually.
Please mark this correct & helpful if it answered your question.
Thanks & Regards,
Sharjeel
Muhammad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-02-2020 06:02 PM
Hi
if it is answered, please be kind to mark my response as CORRECT so that others can reference this in the future and benefited by this. If you have any questions please feel free to ask, I would love to help.
Thanks & Regards,
Sharjeel
Muhammad