Scheduled job support
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 09:22 AM
Hi all, I need a SJ to run on weekly basis and check for ITIL group. If user logged into system (last logged in) is more than 30 days , remove user from ITIL group and send notification to user and one more notification to servicenow support team . Pls help me on how to achieve this requirement .
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 09:44 AM
Here are helpful and already available code. Do it from Flow not from SJ
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0790116
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 09:53 AM
Hi @Vijaykumar K ,
U can try this below code in ur scheduled Job. Create a SJ which runs weekly & under script area paste below script. test it in lower environment & check. User proper backend names & sys ID's of group wherever required.
var usrGrp = new GlideRecord('sys_user_grmember');
usrGrp.addEncodedQuery('user.last_login_timeMORETHANsys_created_on@day@after@30^group=ed156a311b70ec10741b620be54bcb10');
usrGrp.query();
while(usrGrp.next()){
gs.eventQueue('send_notif_user',usrGrp,usrGrp.user.email); //Create a notification for sending to user which will trigger based upon this event select event parm1 contains receipient checkbox
gs.eventQueue('send_notif_servicenowteam',usrGrp); //Create a notification for sending to Servicenow Support team based upon this event(whom to send hardcode servicenow support team name)
usrGrp.deleteRecord();
}
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 08:50 PM
HI @Vijaykumar K ,
I trust you are doing great.
Here is a basic script outline. You need to modify it according to your exact requirements and system configuration:
var gr = new GlideRecord('sys_user_group'); // Replace with your group table name
gr.addQuery('name', 'ITIL'); // Replace with your group's name
gr.query();
while (gr.next()) {
var userGR = new GlideRecord('sys_user');
userGR.addQuery('sys_id', gr.user); // Assuming 'user' is the reference field to sys_user
userGR.addQuery('last_login_time', '<', gs.daysAgo(30));
userGR.query();
while (userGR.next()) {
// Remove user from group
gr.deleteRecord();
// Send notification to user
gs.eventQueue('your.event.name.user', gr, userGR.sys_id, userGR.email);
// Send notification to support team
gs.eventQueue('your.event.name.support', gr, 'support team details', 'support team email');
}
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2023 08:56 AM
Hi @Amit Gujarathi Thnks for the suggestion.
Hope you are doing well
Could you pls help me on how to send notification to user and service now support team DL. That event part I don't get it actually.
Thanks