create email notification for a inactive user of the group

Shruthi1987
Tera Contributor

Hi All,

 

It is first time to work on the wmail notification. I need to create an email notification the following conditions where the target groups are those that start with API..
1. When a ServiceNow Group member's account becomes inactive: Emails will be sent to the Group Manager and Group Member, with cc to the CMDB team
2. When a ServiceNow Group manager's account becomes inactive: Emails will be sent to the Group Member, with cc to the CMDB team

Can I create both the condition in one email notification or need to create separate notification?
Can it be done with email notification setting or should I use flow designer?

It will be helpful if anybody help me with script to send the notification for the above conditions? 

 

Thank you.

 

7 REPLIES 7

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Shruthi1987 

 

I don't have the script; the experts will share it later. However, you can handle this via Flow Designer. You'll need one flow with a condition to check both members and their manager. Here's the catch: if one member is inactive or you need all members to be active, then the email should go out.

*************************************************************************************************************
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]

****************************************************************************************************************

Bhupender
Tera Expert

you need to create separate email notifications for each condition. This ensures that each notification is triggered and sent based on the specific criteria.

Creating Email Notifications: 

Go to System Notification > Email > Notifications.

Click New 

  1. First Notification: Group member's account becomes inactive.

    • Name: Enter a name for the notification.

    • Table: Set it to User [sys_user].

    • When to Send: Choose the condition "when a record is updated".

    • Condition: Set the condition to active changes to false and member of group starts with API.

    • Who will receive: Choose Group Manager and Group Member.

    • CC: Add the CMDB team.

and script for this is 

'' 
var user = new GlideRecord('sys_user');
user.get(current.user_id);


var group = new GlideRecord('sys_user_grmember');
group.addQuery('user', user.sys_id);
group.query();
while (group.next()) {
var groupName = group.getValue('group');
if (groupName.startsWith('API')) {
var email = new GlideEmailOutbound();
email.setSubject("Group Member Inactive");
email.setBody("The account of group member " + user.getValue('name') + " has become inactive.");
email.setTo(group.getValue('manager.email'));
email.addAddress('cc', 'cmdb_team@example.com');
email.send();
break;
}
}; ''

 

Second Notification: Group manager's account becomes inactive.

  • Name: Enter a name for the notification (e.g., "Group Manager Inactive").

  • Table: Set it to User [sys_user].

  • When to Send: Choose the condition "when a record is updated".

  • Condition: Set the condition to active changes to false and manager of group starts with API.

  • Who will receive: Choose Group Member.

  • CC: Add the CMDB team.

script for this is 

 

'' var user = new GlideRecord('sys_user');
user.get(current.user_id);

var group = new GlideRecord('sys_user_grmember');
group.addQuery('manager', user.sys_id);
group.query();
while (group.next()) {
var groupName = group.getValue('group');
if (groupName.startsWith('API')) {
var email = new GlideEmailOutbound();
email.setSubject("Group Manager Inactive");
email.setBody("The account of group manager " + user.getValue('name') + " has become inactive.");
email.setTo(group.getValue('user.email'));
email.addAddress('cc', 'cmdb_team@example.com');
email.send();
break;
}
}; ''

Ankur Bawiskar
Tera Patron
Tera Patron

@Shruthi1987 

Best to handle it via 2 different flows so that it allows you for future enhancements.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Sai_Charan_K
Kilo Sage

Hi @Shruthi1987,
Using flow designer would be a better approach over here like @Dr Atul G- LNG  has mentioned. Please find the attached flow which I developed to fulfill your requirement. 
 Flow.jpg


Trigger condition is set to user table where the condition is created or updated and active is false.

The flow looks for group records where the user is the manager and the name of the group is starting with "APP" and sends an email to the group email and anyone else you require in the first 3 steps. The further steps check whether the user is a member of groups starting with "APP" and sends a notification to the group manager and anyone else you require.

This flow is tested in my PDI and it works fine. Please find the below snippet of the test results.

Sai_Charan_K_1-1739531768763.png

Please mark my answer "Helpful" and "correct" if you feel that it has helped you in any way.

Thanks and Regards,
K. Sai Charan
Sr. ServiceNow Developer
Deloitte India