How to get inactive members in each group and an email should trigger to individual manager
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2024 05:36 AM
Hi All,
I am working on a requirement to get inactive members in each group and to send an email to managers with the inactive user details in their group
--> i am trying with below code :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2024 06:07 AM
I'm not Ankur, so you can ignore the answer if you are just wanting his input (tagging really is the 2nd annoying thing)...
Create a flow for it. You can trigger flows on a schedule as well. From there you can easily do a lookup to the groups with inactive user and use the send email action to trigger it to be received by the group manager. If you use a 'for each' to check on all inactive users, you can put them in the email. You could even make it one email per manager if you don't want multiple emails for one person managing more groups.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2024 06:16 AM
Hi @shabbir5
To achieve this, you need to perform the following steps:
- Query Inactive Members: Retrieve inactive users in each group and their managers.
- Aggregate Data: Collect inactive user details for each group and prepare the data for email.
- Send Email: Use the gs.eventQueue to trigger an event that will send an email to the managers with the collected data.
- Schedule the Job: Create a scheduled job to run this script every 6 months.
Here is the complete solution to your requirement:
Steps -
Create Notification:
- Go to System Notification > Email > Notifications.
- Create a new notification with:
- Name: Inactive User Notification
- Table: Global
- When to send: Event is fired
- Event Name: custom.inactive.user.notification
Set Email Subject and Body:
- Subject: Inactive Users in Your Group
- Email Body: Use the emailBody passed in the event.Who will receive: Users/Groups as needed (or use a script to send to the dynamic recipientCreate Scheduled Job
Create a Scheduled Job:
- Navigate to System Definition > Scheduled Jobs.
- Create a new Scheduled Script Execution with:
- Name: Send Inactive User Notifications
- Run: Periodically
- Repeat Interval: Every 6 months
Script for Scheduled Job:
(function() {
var gr = new GlideAggregate('sys_user_grmember');
gr.addQuery('user.active', false);
gr.groupBy('group');
gr.query();
var groupDetails = {};
while (gr.next()) {
var groupID = gr.getValue('group');
var groupName = gr.group.name.toString();
var groupManager = gr.group.manager.user_name.toString();
if (!groupDetails[groupID]) {
groupDetails[groupID] = {
name: groupName,
manager: groupManager,
users: []
};
}
var inactiveUserGR = new GlideRecord('sys_user_grmember');
inactiveUserGR.addQuery('group', groupID);
inactiveUserGR.addQuery('user.active', false);
inactiveUserGR.query();
while (inactiveUserGR.next()) {
groupDetails[groupID].users.push({
name: inactiveUserGR.user.name.toString(),
email: inactiveUserGR.user.email.toString()
});
}
}
for (var groupID in groupDetails) {
var groupInfo = groupDetails[groupID];
var emailBody = 'Dear ' + groupInfo.manager + ',\n\n';
emailBody += 'The following users in your group "' + groupInfo.name + '" are inactive:\n\n';
groupInfo.users.forEach(function(user) {
emailBody += '- ' + user.name + ' (' + user.email + ')\n';
});
emailBody += '\nPlease review and take necessary action.\n\nBest Regards,\nYour Company';
// Trigger the email event
gs.eventQueue('custom.inactive.user.notification', null, groupInfo.manager, emailBody);
}
})();
This script will collect inactive users for each group and send an email to the respective group managers every 6 months.
Please mark as helpful if this helps
Regards
Akshay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2025 03:11 AM
1. This is helpful. But when we are writing everything in the scheduled job script why do we require email notification?
2. Only to send out to managers or particular group we are create a notification.
3. how to link notification n scheduled job script here?
If you can respond on this please?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2024 10:44 AM
Hi ,
Please use this Script :