how can i set mail to a perticular group on some condtion in email script(sys_script_email)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 02:22 AM
There is a requirement where i need to write a script with if else condtion , when if condtion is met then all the users of group abc should recieve notification otherwise only requester and its manager
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 02:30 AM - edited 02-14-2024 02:31 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 02:36 AM
Below is sample business rule code , please modify as per your fields
(function executeRule(current, previous /*null when async*/) {
// Check if the condition is met
if (conditionIsMet(current)) {
// If the condition is met, send notification to all users in the group "abc"
sendNotificationToGroupMembers("abc");
} else {
// If the condition is not met, send notification to requester and requester's manager
sendNotificationToRequesterAndManager(current);
}
})(current, previous);
// Function to check if the condition is met
function conditionIsMet(current) {
// Add your logic here to determine if the condition is met
// For example, you might check some fields on the current record
return current.someField === "someValue";
}
// Function to send notification to all users in a group
function sendNotificationToGroupMembers(groupName) {
// Get users in the specified group
var groupMembers = new GlideRecord('sys_user_grmember');
groupMembers.addQuery('group', 'IN', groupName);
groupMembers.query();
while (groupMembers.next()) {
// Send notification to each user in the group
sendNotification(groupMembers.user.toString());
}
}
// Function to send notification to requester and requester's manager
function sendNotificationToRequesterAndManager(current) {
// Get requester's ID from the current record
var requesterId = current.requested_for.toString();
// Send notification to requester
sendNotification(requesterId);
// Get requester's manager ID
var managerId = getManagerId(requesterId);
// Send notification to requester's manager
sendNotification(managerId);
}
// Function to get manager's ID
function getManagerId(userId) {
var user = new GlideRecord('sys_user');
user.get(userId);
// Assuming manager field is "manager" - update it if your instance uses a different field
return user.manager.toString();
}
// Function to send the actual notification
function sendNotification(userId) {
// Add your notification logic here
gs.info("Sending notification to user: " + userId);
// ... Add code to send notification
}
Kindly mark helpful/accepted if it helps you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 02:51 AM
Please take a look on the below Link which has similar Solution
Let me know if that doesn't work !!
Regards,
Shyamkumar
Regards,
Shyamkumar