- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 12:28 AM
Hi Team,
We need to send an email notification everyday,
if assignment group has no members or group owner is empty or group manager is empty with all the group details.
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 02:28 AM
you can handle this easily without scripting using Flow
1) Trigger flow daily at particular time
2) Lookup on task table where assignment group is not empty and active=true
3) then use For Each to iterate those tasks
4) Inside the for each, use Lookup record on sys_user_grmember table with this Group
5) 1 more Lookup record on Group table with Group=Previous group and manager EMPTY
5) If either conditions satisfy then send email
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-22-2025 12:37 AM
Hello @Kaustubh k
You can create a scheduled job which triggers daily if an assignment group has no members, no group owner, or no group manager.
Below is sample script you can use in scheduled job under script section.
(function() {
var gr = new GlideRecord('sys_user_group');
gr.query();
while (gr.next()) {
var groupName = gr.name.toString();
var groupOwner = gr.getValue('u_owner'); //Replace field name as per your instance
var groupManager = gr.getValue('manager');
// Check if the group has no members
var memberCount = new GlideAggregate('sys_user_grmember');
memberCount.addQuery('group', gr.sys_id);
memberCount.addAggregate('COUNT');
memberCount.query();
memberCount.next();
var hasMembers = memberCount.getAggregate('COUNT') > 0;
// Check if owner or manager is empty
if (!hasMembers || !groupOwner || !groupManager) {
// Send email notification
var email = new GlideEmailOutbound();
email.setSubject('Group Details Missing');
email.setFrom('your_email@example.com');
email.setTo('recipient@example.com');
email.setBody('Group: ' + groupName + '\n' +
'Owner: ' + (groupOwner || 'None') + '\n' +
'Manager: ' + (groupManager || 'None') + '\n' +
'Members: ' + (hasMembers ? 'Present' : 'None'));
email.send();
}
}
})();
If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.
Thanks & Regards
Viraj Hudlikar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 01:30 AM
Hello @Kaustubh k ,
I would recommend you to first create one event & notification and write the below schedule job that will help to trigger the notification.
var inc = new GlideRecord("incident");
inc.query();
while (inc.next()) {
var gr1 = inc.assignment_group;
var group = new GlideRecord("sys_user_group");
group.addQuery("name", gr1);
group.query();
while (group.next()) {
var grName = group.name.toString();
var grOwner = group.getValue('u_owner');
var grManager = group.getValue('manager');
var mem = new GlideRecord("sys_user_grmember");
mem.addQuery("group",grName);
mem.query();
while(!mem.next() || !grOwner || !grManager){
gs.eventQueue("event_name",current,current.assignment_group); // your event name
}
}
}
Create one notification as per your requirement and trigger that notification via event and also fire the event by schedule job that will minimize the performance impact or load on the system.
Please mark my answer as accepted solution and give thumbs up, if it helps you.
Regards,
Abhishek Thakur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 02:28 AM
you can handle this easily without scripting using Flow
1) Trigger flow daily at particular time
2) Lookup on task table where assignment group is not empty and active=true
3) then use For Each to iterate those tasks
4) Inside the for each, use Lookup record on sys_user_grmember table with this Group
5) 1 more Lookup record on Group table with Group=Previous group and manager EMPTY
5) If either conditions satisfy then send email
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-22-2025 07:00 PM
Hope you are doing good.
Did my reply answer your question?
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