what i trying to do is add rows to the notifications based on the selected vendor_count. if two is selected then two rows will be populated with the given information.
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// Initialize the company and requisition GlideRecords
var company = new GlideRecord('core_company');
company.get(current.company); // Get company record using the company's sys_id
var requisition = new GlideRecord('x_jade_procurement_it_purchase_requisition');
requisition.get(current.sys_id); // Get requisition record using the requisition's sys_id
// Initialize email body variable
var emailBody = "";
// Add company information in table format with blue headers
emailBody += "<h2>Company Information</h2>";
emailBody += "<table border='1' style='width:100%; border-collapse: collapse;'>";
// Add blue color to the company table headers
emailBody += "<tr style='background-color: #007bff; color: white;'>";
emailBody += "<th>Vendor Name</th>";
emailBody += "<th>Quotation</th>";
emailBody += "<th>Unit Quantity</th>";
emailBody += "<th>Price Per Unit</th>";
emailBody += "<th>Total</th>";
emailBody += "</tr>";
// Add rows for each vendor depending on vendor count
if (requisition.vendor_count >= 1) {
// First vendor
emailBody += "<tr>";
emailBody += "<td>" + requisition.vendor_1.getDisplayValue() + "</td>";
emailBody += "<td>" + requisition.quotation_1.getDisplayValue() + "</td>";
emailBody += "<td>" + requisition.unit_quantity_1 + "</td>";
emailBody += "<td>" + requisition.price_per_unit_1 + "</td>";
emailBody += "<td>" + requisition.total_1 + "</td>";
emailBody += "</tr>";
}
if (requisition.vendor_count >= 2) {
// Second vendor
emailBody += "<tr>";
emailBody += "<td>" + requisition.vendor_2.getDisplayValue() + "</td>";
emailBody += "<td>" + requisition.quotation_2.getDisplayValue() + "</td>";
emailBody += "<td>" + requisition.unit_quantity_2 + "</td>";
emailBody += "<td>" + requisition.price_per_unit_2 + "</td>";
emailBody += "<td>" + requisition.total_2 + "</td>";
emailBody += "</tr>";
}
if (requisition.vendor_count >= 3) {
// Third vendor
emailBody += "<tr>";
emailBody += "<td>" + requisition.vendor_3.getDisplayValue() + "</td>";
emailBody += "<td>" + requisition.quotation_3.getDisplayValue() + "</td>";
emailBody += "<td>" + requisition.unit_quantity_3 + "</td>";
emailBody += "<td>" + requisition.price_per_unit_3 + "</td>";
emailBody += "<td>" + requisition.total_3 + "</td>";
emailBody += "</tr>";
}
emailBody += "</table>";
// Add requisition details with blue headers
emailBody += "<h2>Requisition Details</h2>";
emailBody += "<table border='1' style='width:100%; border-collapse: collapse;'>";
// Add blue color to the requisition table headers
emailBody += "<tr style='background-color: #007bff; color: white;'>";
emailBody += "<th>Requisition Number</th>";
emailBody += "<th>Requestor Name</th>";
emailBody += "<th>Assigned To</th>";
emailBody += "<th>Short Description</th>";
emailBody += "<th>Delivery Location</th>";
emailBody += "<th>Status</th>";
emailBody += "<th>Description</th>";
emailBody += "<th>Quantity</th>";
emailBody += "<th>Department</th>";
emailBody += "</tr>";
// Ensure requisition record is retrieved successfully before accessing its fields
if (requisition.isValidRecord()) {
emailBody += "<tr>";
emailBody += "<td>" + requisition.requisition_no + "</td>"; // Requisition Number
emailBody += "<td>" + requisition.requester_name.getDisplayValue() + "</td>"; // Requestor Name
emailBody += "<td>" + requisition.assigned_to.getDisplayValue() + "</td>"; // Assigned To
emailBody += "<td>" + requisition.short_description + "</td>"; // Short Description
emailBody += "<td>" + requisition.delivery_location.getDisplayValue() + "</td>"; // Delivery Location
emailBody += "<td>" + requisition.status + "</td>"; // Status
emailBody += "<td>" + requisition.description + "</td>"; // Description
emailBody += "<td>" + requisition.quantity + "</td>"; // Quantity
emailBody += "<td>" + requisition.department.getDisplayValue() + "</td>"; // Department
emailBody += "</tr>";
} else {
emailBody += "<tr><td colspan='9'>No requisition details available.</td></tr>";
}
emailBody += "</table>";
// Print email body to template
template.print(emailBody);
})(current, template, email, email_action, event);
here is the snipate of the email notification :
here in the company information there will be two rows in the company section if the vendor count is 2 .
script is not working
please help!!