Send notification once at 30 days and 60 days
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 09:05 AM
Hi,
I am not sure I am putting this in the right forum but hope someone can assist.
I have created 2 notifications to send to ITIL users that have not logged in for over 30 days and 60 days.
Scenario 1:
ITIL user has not logged in for over 30 days
Event: Last.login
Notification: ITIL users not logged in for over 30 day
- Send When: Event is fired
Scheduled job: Send ITIL not logged in for 30 days
- var gr = new GlideRecord('sys_user');
gr.addEncodedQuery('roles=ITIL^active=true^last_login<javascript:gs.beginningOfLast30Days()^ORlast_loginISEMPTY');
gr.query();
while(gr.next()){
gs.eventQueue("Last.login", gr);
}
- var gr = new GlideRecord('sys_user');
- Job runs daily
- Issue: Some users are getting the email notification every day and I only need it to send to them once
Scenario 2:
ITIL Users not logged in for over 60 days
Created in Dev:
Event: Last.login60
Notification: ITIL users not logged in for over 60 day
- Send when: Event is fired
Scheduled job: Send ITIL not logged in for 60 days
- var gr = new GlideRecord('sys_user');
gr.addEncodedQuery('roles=ITIL^active=true^last_login<javascript:gs.beginningOfLast60Days()^ORlast_loginISEMPTY');
gr.query();
while(gr.next()){
gs.eventQueue("Last.login60", gr);
}
- var gr = new GlideRecord('sys_user');
- Job runs daily
- Issue: Some users are getting the email notification every day and I only need it to send to them once
I would appreciate any assistance on how to have the job run daily but only send the notification to the user once.
Thanks,
Gina
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 11:34 AM
Hello @Bridgina Starr
Can you please try the below code
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery('roles=ITIL^active=true^last_login<javascript:gs.daysAgoStart(30)');
gr.query();
while(gr.next()){
gs.eventQueue("Last.login", gr);
}
Don't forget to mark my answer as Correct & Helpful, if applicable.
Krishna Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 11:34 AM
Here are a couple different ideas that you could try:
- Change your encoded query so that it only runs when the last_login is equal to the 30 or 60 days, rather than using "<". This could work if the job is running every day and if a last_login value exists. This wouldn't work for users that have already had their last_login time exceeding 60 days.
- Add a hidden field to sys_user to keep track of whether or not that user has had a notification already. For example, you could have a date field that stores when they were sent their most recent last login notification. That way, your encoded query could check the last_login date as well as the previous last login notification timestamp to determine whether or not another notification should be sent.
I'm sure there are other solutions out there, but those were two fairly simple ideas that came to mind right off the bat. The system would need a way to know that the notification has already been sent, so as long as you could give it a way to record that, you should be able to accomplish your goal.
Hope that helps point you in the right direction!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 10:44 AM
Hi,
I thought about trying your suggestion, "Change your encoded query so that it only runs when the last_login is equal to the 30 or 60 days, rather than using "<". This could work if the job is running every day and if a last_login value exists. This wouldn't work for users that have already had their last_login time exceeding 60 days.".
But I am hesitant as I still feel like this will send the same user an email everyday if they don't login. I only want to send it to them once.
I do appreciate your input. I am trying something else and if that does not work, I will be trying your second suggestion of adding a "hidden field".
Thanks,
Gina
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 01:09 PM
A simple solution would be checking if 'email notification has already been sent for the user' before you trigger the event with the user gliderecord i.e
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery('roles=ITIL^active=true^last_login<javascript:gs.beginningOfLast60Days()^ORlast_loginISEMPTY');
gr.query();
while(gr.next()){
//check if email has already been sent for the same user lets say in last X days
var emailGR = new GlideRecord('sys_email');
emailGR.addEncodedQuery(); //Query should be created at or after X days AND Subject LIKE <ITIL not logged in> AND Recipients Contains gr.user.email_id
emailGR.query();
//If any email is NOT found for this user in last X days trigger the event
If(!emailGR.next()){
gs.eventQueue("Last.loginX", gr);
}
}
Please mark the response as helpful if it resolves your issue