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

Hello @Sai_Charan_K ,

Thank you soo much for your prompt support. 

Could you please help me to know how can I send email to all the group members dynamically when there is no group email address ?

 

Hi @Shruthi1987 ,

In order to send email to individual group members along with group email, you can lookup group records for the groups which the user is manager and for each group member you can send the email. Please check the below screenshot for reference.

Sai_Charan_K_0-1739793436425.png

In step no. 5 in "To" field add the user's email from step no. 4 to send the emails to the group members along with the group mail.


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

sunil maddheshi
Tera Guru

@Shruthi1987 

ou have two different conditions for triggering email notifications:

  1. When a Group Member becomes inactive
  2. When a Group Manager becomes inactive

Should I create one or two notifications?

It's best to create two separate notifications because:

  • Each condition has different recipients.
  • It will be easier to manage and troubleshoot.
  • ServiceNow notifications trigger based on conditions, so separating them ensures accuracy.

Can it be done using Email Notifications or Flow Designer?

  • If you want a simple solution, use Email Notifications in ServiceNow. This works if the conditions can be set using standard filters.
  • If more flexibility is needed (e.g., advanced logic or multiple conditions), use Flow Designer with an action to send emails.

Steps to Configure Email Notification (Using Email Notification Module)

  1. Navigate to: System Notification > Email > Notifications
  2. Click "New" to create a new notification.
  3. Fill in details:
    • Name: Notify on Group Member Inactivation
    • Table: sys_user
    • Condition: Active is false AND Group starts with API
  4. Who will receive?
    • To: Group Manager (group.manager)
    • CC: CMDB Team (Add manually or use a group field)
  5. Add email template: Define your subject and message.
  6. Save and Activate the Notification.

Repeat these steps for the Group Manager condition.

Using Flow Designer (For Advanced Logic)

If you want more control, use Flow Designer:

  1. Navigate to: Flow Designer > Create a new Flow
  2. Trigger: When a sys_user record is updated
  3. Condition: Active is false AND Group starts with API
  4. Action: Use Send Email action
  5. Define Recipients: Use Lookup Records to find the right group manager/members.
  6. Save and Activate the Flow.

Script Example for Flow Designer (If Needed)

If you need a script to dynamically send emails, you can use a script action in Flow:

 

(function executeRule(current, previous /*null when async*/) {
    var group = current.getValue('sys_user_group'); 
    if (group && group.startsWith('API')) { 
        var emailRecipients = [];
        var grGroup = new GlideRecord('sys_user_group');
        if (grGroup.get(group)) {
            // Add Group Manager
            if (grGroup.manager) {
                emailRecipients.push(grGroup.manager.email);
            }
            // Add Group Members
            var grMembers = new GlideRecord('sys_user_grmember');
            grMembers.addQuery('group', group);
            grMembers.query();
            while (grMembers.next()) {
                emailRecipients.push(grMembers.user.email);
            }
        }
        // Send Email
        gs.eventQueue("custom.email.notification", current, emailRecipients.join(','), "CMDB_Team@example.com");
    }
})(current, previous);