how to found the gropus with inactive users
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 12:59 AM
Hi All,
As per the requirement , for every 3 months we would like to send an email to groups managers with all the inactve members available in that group.
mail should contain , group name and list of inactive users in that group.
please provide your siggestions @Ankur Bawiskar
Thank you,
Shabbir Shaik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 01:17 AM
Hi @shabbir5
1st part to get the inactive members
Report and condition:
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
01-24-2024 01:35 AM - edited 01-24-2024 01:44 AM
Hi @shabbir5 ,
You can create a schedule job, event , notification that does this every 3months for you...
var groups = new GlideRecord('sys_user_group');
groups.query();
while (groups.next()) {
var groupName = groups.name.toString();
// Get group managers
var managers = [];
var manager = new GlideRecord('sys_user_grmember');
manager.addQuery('group', groups.sys_id);
manager.addQuery('group.manager', true);
manager.query();
while (manager.next()) {
managers.push(manager.user.toString());
}
// Get inactive members in the group
var inactiveMembers = [];
var user = new GlideRecord('sys_user');
user.addQuery('active', false);
user.query();
while (user.next()) {
var membership = new GlideRecord('sys_user_grmember');
membership.addQuery('user', user.sys_id);
membership.addQuery('group', groups.sys_id);
membership.query();
if (membership.next()) {
inactiveMembers.push(user.name.toString());
}
}
if (inactiveMembers.length > 0) {
trigger event of notifcation here....
}
}
I hope this helps... Adjust the script accordingly
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 01:25 AM
why not create a report for this and use scheduled report and send the report to group managers?
How to Report on Inactive users in Groups
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 01:39 AM
Sure, you can achieve this by creating a scheduled job in ServiceNow. Here are the steps:
1. Navigate to System Definition > Scheduled Jobs in ServiceNow.
2. Click on New to create a new scheduled job.
3. Fill in the necessary details like Name, Description, and when you want the job to run (every 3 months in your case).
4. In the 'Script' field, you need to write a script that fetches all the groups, their managers, and the inactive users in those groups. Here is a sample script:
javascript
var groupGR = new GlideRecord('sys_user_group');
groupGR.query();
while(groupGR.next()) {
var groupName = groupGR.name;
var manager = groupGR.manager;
var inactiveUsers = [];
var userGR = new GlideRecord('sys_user');
userGR.addQuery('active', false);
userGR.addQuery('group', groupGR.sys_id);
userGR.query();
while(userGR.next()) {
inactiveUsers.push(userGR.name);
}
if(inactiveUsers.length > 0) {
gs.eventQueue('custom.event.send.email', groupGR, manager, inactiveUsers.join(','));
}
}
5. This script fetches all the groups and their managers. It then queries for inactive users in each group. If there are any inactive users, it triggers a custom event to send an email. The event name is 'custom.event.send.email' and it passes the group record, manager, and a comma-separated list of inactive users as parameters.
6. You need to create a new email notification that listens to the 'custom.event.send.email' event. Navigate to System Policy > Email > Notifications and create a new notification. In the 'When to send' section, select 'When an event is fired' and enter 'custom.event.send.email' as the event name.
7. In the 'Who will receive' section, select 'Specific User' and use the script ${event.parm1} to get the manager from the event parameters.
8. In the 'What it will contain' section, you can customize the email body to include the group name and list of inactive users. You can use ${event.parm1.name} to get the group name and ${event.parm2} to get the list of inactive users.
9. Save the notification.
10. Now, every 3 months, the scheduled job will run and send an email to each group's manager with the list of inactive users in their group.
For ServiceNow Live Classes, Books, Sample Resumes, Interview Questions, CSA Quizzes.
And getting better services's on ServiceNow you can visits our website.
Please visit : https://nowkb.com/home
Our Website :https://nowkb.com/home
nowKB.com