Sending a dynamic email based on a user field

nabeel55
Tera Contributor

Requirement : Send Notification when user’s department is changed.

 

  1. Check User that they are in any Group Member or not.
  2. If that User is in Group Member, system remove user who change department from their previous Group Member automatically. (User should be removed from all the groups)
  3. Send notify mail to inform the previous Group Manager that the Changed department User already removed from Group, because of their department changed.
  4. If Group Manager still need to add this User back in the previous Group, can be added manually.

 

 Mail Notification: Notification can be sent when user department changed. Need ServiceNow system to send mail notify to previous Group Manager

UC1: Notify mail to the previous Group Manager

Email to (who): Notification to the previous [Group Managers] that user is removed off.

Email Body (what): User (ID and Name) department changed from Previous Department to New Department on Detected Date, and already removed from Group Member automatically.

Email Subject:  ServiceNow User Department change detected

Member name: [FirstName-LastName]

Effected Group name: Previous [GroupName]

Status: [Status]

Detected date: [xxx]

Actions: To be notified the updated group members

User is automatically removed from Group.

 How many notifications to be sent?  1 time when that user automatically removed from Group.

2 REPLIES 2

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @nabeel55 

 

Whats you problem statement here?  everything is clear and you build the flow from this. 

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

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

nabeel55
Tera Contributor

with business rule script i got all the required managers in an array named managers and now want to send a notification to the list of managers who is stored in the managers array with the notification how do i do that?

how do i call array managers in email script? 

here is the business rule script i used to get managers

// Function to get the managers from the previous groups of the user
function getManagersFromPreviousGroups(userId) {
    var managers = [];

    // Query sys_user_grmember to get the previous groups
    var grMemberGR = new GlideRecord('sys_user_grmember');
    grMemberGR.addQuery('user', userId);
    grMemberGR.query();

    while (grMemberGR.next()) {
        // For each group the user was a member of, get the manager
        var groupName = grMemberGR.getValue('group');
        var manager = getManagerFromGroup(groupName);

        // If a manager is found, add it to the list of managers
        if (manager) {
            managers.push(manager);

            // Automatically remove the user from the group member
            grMemberGR.deleteRecord(); // This deletes the sys_user_grmember record
        }
    }

    // Send notification to managers
    sendNotificationToManagers(managers);

    return managers;
}

/