send email to manager including employee name inside email body Multirowvariable set
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2024 10:00 PM
Hi experts,
We have MRVS record producer with variables Employee and Manager. Currently we event triggered by Business rule that is sending email notification to each manager in each row separately.
How can add employee name related to each row manager in the email body. Current email script is displaying employee from all rows.
for example, in the below scenario currently is going to John and Gaurang separately but in both emails, Despina and JT Holtshlag names are displayed in email body.
Requirement: in the email sent to john, only employee Desipina name should be in email body
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// Add your code here
var mrvs;
mrvs = current.variables.for_my_employee_s; //mention your mrvs internal name here
var rowCount = mrvs.getRowCount();
for (var i = 0; i < rowCount; i++) {
var row = mrvs.getRow(i);
var grp = new GlideRecord('sys_user');
grp.addQuery('sys_id', row.employee_name);
grp.query();
if (grp.next()) {
template.print(grp.name);
}
}
})(current, template, email, email_action, event);
TIA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2024 11:44 PM
- Hi @si21
Below is an example email script for your notification:
How It Works
Fetch MRVS Data: The current.variables[mrvsName] holds the JSON data of the MRVS. You parse it using JSON.parse().
Filter by Manager: Match the manager.email field in the MRVS rows with the current email recipient’s email (email.to).
Build and Print the Email Body: Dynamically construct a string containing only the employee names associated with the current manager and print it into the email.
Example Scenario
MRVS Data:
Email to John:
Email to Gaurang:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2024 01:24 AM
Hi @Brad Bowman , could you please provide your inputs here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2024 01:52 AM
Hello @si21
Please try this script
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
// Retrieve the MRVS variable
var mrvs = current.variables.for_my_employee_s; // Replace with your MRVS internal name
var rowCount = mrvs.getRowCount();
// Get the email recipient (manager)
var emailRecipient = email.recipients.toString();
// Initialize a variable to store employees for this recipient
var employeeNames = [];
// Loop through each row in the MRVS
for (var i = 0; i < rowCount; i++) {
var row = mrvs.getRow(i);
// Check if the manager's email matches the recipient email
if (row.employee_manager.email == emailRecipient) {
// Add the employee's name to the array
employeeNames.push(row.employee_name.getDisplayValue());
}
}
// If employees are found for the manager, include them in the email body
if (employeeNames.length > 0) {
template.print("The following employees are associated with you:<br>");
template.print(employeeNames.join("<br>"));
} else {
template.print("No employees are assigned to you in this request.");
}
})(current, template, email, email_action, event);
"If you found my answer helpful, please give it a like and mark it as the "accepted solution". It helps others find the solution more easily and supports the community!"
Thank You
Juhi Poddar