- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2022 01:01 AM
A notification that will remind users that haven’t login to their account for the last 4 months and a scheduled job that will trigger the notification created above every 15th of the month. Another 2nd notification that will inform the users that received the 1st notification. A Scheduled job that will trigger every 30th of the month with the following:
Store the roles of the user (haven’t login to their account for the last 4 months) in custom table named Archived User Roles (u_ar_sys_user_has_role) Trigger the notification mentioned and remove roles of the user/s.
What I did:
I created event:remind.user.login
I created email Notification: Eval Notification- haven’t login
I created Schedule Job:
===
var gr = new GlideRecord('sys_user');
gr.addNotNullQuery('last_login_timeRELATIVELT@month@ahead@4');
gr.query();
var gdt = new GlideDateTime();
gdt.addDaysUTC(-360);
while(gr.next())
{
if(gr.getValue('last_login') < gdt.getLocalDate())
{
gs.eventQueue('remind.user.login', gr, gr.user_name, gr.email);
}
}
===
Not working. What I am missing? Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2022 03:19 AM - edited 10-09-2022 03:25 AM
I have tried to implement your requirement and it seems to be working for me. Below are the steps which I have used for 1st notification.
- Created an event for 1st notification which will be triggered on 15th of every month.
- Created 1st Notification which will be sent when 1st event will be triggered.
Created system property which will store emails of those users to whom the 1st notification was sent.
Created 1st scheduled job which will trigger the 1st event.
var grUser = new GlideRecord('sys_user');
grUser.addActiveQuery();
grUser.addEncodedQuery('last_loginRELATIVELT@month@ago@4');
grUser.query();
var emails = [];
while(grUser.next()){
if(!grUser.email.nil()){
gs.eventQueue('community.answer.last.login.notification', grUser, grUser.getValue('email'));
emails.push(grUser.getValue('email'));
}
}
if(emails.length > 0){
gs.setProperty('community.answer.last.login.notification', emails.join());
}else{
gs.setProperty('community.answer.last.login.notification', '');
}
Output/Result:
Below are the steps which I have used for 2nd notification.
- Created 2nd event for 2nd notification which will be triggered on 30th of every month.
- Created 2nd Notification which will be sent when 2nd event will be triggered.
- Created 2nd scheduled job which will trigger the 2nd event.
var grUser = new GlideRecord('sys_user');
grUser.addActiveQuery();
var emails = gs.getProperty('community.answer.last.login.notification');
grUser.addEncodedQuery('emailIN' + emails);
grUser.query();
while (grUser.next()) {
gs.eventQueue('community.answer.last.login.2nd.notifica', grUser, grUser.getValue('email'));
/*var grGroup = new GlideRecord('sys_user_grmember');
grGroup.addQuery('user', grUser.getValue('sys_id'));
grGroup.query();
while(grGroup.next()){
grGroup.deleteRecord();
}*/
}
gs.setProperty('community.answer.last.login.notification', '');
Output/Result:
Above steps might help you fulfil your requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2022 06:14 AM
Hello,
As the script is written in scheduled job you can use execute now to trigger the schedule job
So first do the execute now for 1st scheduled job and check if the notification got triggered for users by
Going to sent in Navigation:-
And then see if all the notification go triggered to the users or not
Then once you confirm that you can trigger the second scheduled job by clicking on execute button
And then again go to sent and see if the second notification got triggered or not:-
Please mark my answer as correct based on Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2022 07:38 AM
I see that you have written the System property name as system.property.last.login.notification
and in the script you are using last.login.notification, please check if you are using the correct name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2022 03:19 AM - edited 10-09-2022 03:25 AM
I have tried to implement your requirement and it seems to be working for me. Below are the steps which I have used for 1st notification.
- Created an event for 1st notification which will be triggered on 15th of every month.
- Created 1st Notification which will be sent when 1st event will be triggered.
Created system property which will store emails of those users to whom the 1st notification was sent.
Created 1st scheduled job which will trigger the 1st event.
var grUser = new GlideRecord('sys_user');
grUser.addActiveQuery();
grUser.addEncodedQuery('last_loginRELATIVELT@month@ago@4');
grUser.query();
var emails = [];
while(grUser.next()){
if(!grUser.email.nil()){
gs.eventQueue('community.answer.last.login.notification', grUser, grUser.getValue('email'));
emails.push(grUser.getValue('email'));
}
}
if(emails.length > 0){
gs.setProperty('community.answer.last.login.notification', emails.join());
}else{
gs.setProperty('community.answer.last.login.notification', '');
}
Output/Result:
Below are the steps which I have used for 2nd notification.
- Created 2nd event for 2nd notification which will be triggered on 30th of every month.
- Created 2nd Notification which will be sent when 2nd event will be triggered.
- Created 2nd scheduled job which will trigger the 2nd event.
var grUser = new GlideRecord('sys_user');
grUser.addActiveQuery();
var emails = gs.getProperty('community.answer.last.login.notification');
grUser.addEncodedQuery('emailIN' + emails);
grUser.query();
while (grUser.next()) {
gs.eventQueue('community.answer.last.login.2nd.notifica', grUser, grUser.getValue('email'));
/*var grGroup = new GlideRecord('sys_user_grmember');
grGroup.addQuery('user', grUser.getValue('sys_id'));
grGroup.query();
while(grGroup.next()){
grGroup.deleteRecord();
}*/
}
gs.setProperty('community.answer.last.login.notification', '');
Output/Result:
Above steps might help you fulfil your requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2022 05:17 AM
My I ask is there anyway I can test the data? I can see on my outbox as admin the first email, how can I test that the second email is working? Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2022 06:14 AM
Hello,
As the script is written in scheduled job you can use execute now to trigger the schedule job
So first do the execute now for 1st scheduled job and check if the notification got triggered for users by
Going to sent in Navigation:-
And then see if all the notification go triggered to the users or not
Then once you confirm that you can trigger the second scheduled job by clicking on execute button
And then again go to sent and see if the second notification got triggered or not:-
Please mark my answer as correct based on Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2022 06:53 AM