email script not working as expected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2024 09:09 AM
Hi Guys ,
i have requirement where , I need to email in below given format where i am getting data from core_company table and it_purchase_requisition table , but company table values are getting set and for the other table for some fields sys_id is getting populated .
here is the email script :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2024 09:40 AM
You can dot-walk to a field like
requisition.requester_name.name
or try
requisition.requester_name.getDisplayValue()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2024 09:43 AM - edited 10-24-2024 09:44 AM
Hi @tghadage124
You don't need to query the 'x_jade_procurement_it_purchase_requisition' table with sys_id. You can use current in your email script.
Also, you've Missed adding Assignmnet group in the <th> part of your code.
For refernce fields like Assigned to/Assignment group the sys_id's will be populated, You can simply dot-walk to name.
Updated code:
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// Add your code here
var company = new GlideRecord('core_company');
if (company.get('sys_id', current.company)) {
var emailBody = "";
emailBody += "<h2>Company Information</h2>";
emailBody += "<p><strong>Company Name: </strong>" + company.name + "</p>";
emailBody += "<p><strong>Company Address: </strong>" + company.street + "</p>";
emailBody += "<p><strong>Phone: </strong>" + company.phone + "</p>";
emailBody += "<p><strong>City:</strong>" + company.city + "</p>";
emailBody += "<p><strong>Stock Price: </strong>" + company.stock_price + "</p>";
emailBody += "<h2>Requisition Details</h2>";
emailBody += "<table border='1' style='width:100%; border-collapse: collapse;'>";
emailBody += "<tr><th>Requisition Number</th><th>Requestor Name</th><th>Assigned To</th><th>Assignment Group</th><th>Short Description</th><th>Delivery Location</th><th>Status</th><th>Description</th><th>Quantity</th><th>Department</th></tr>";
emailBody += "<tr>";
emailBody += "<td>" + current.requisition_no + "</td>";
emailBody += "<td>" + current.requester_name + "</td>";
emailBody += "<td>" + current.assigned_to.name + "</td>";
emailBody += "<td>" + current.assignment_group.name + "</td>";
emailBody += "<td>" + current.short_description + "</td>";
emailBody += "<td>" + current.status + "</td>";
emailBody += "<td> " + current.description + "</td>";
emailBody += "<td>" + current.quantity + "</td>";
emailBody += "<td>" + current.department + "</td>";
emailBody += "</tr>";
emailBody += "</table>";
//email.setBody(emailBody);
template.print(emailBody);
}
})(current, template, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2024 11:44 PM
Hi @Voona Rohila ,
thanks your reply , that issue is resolved but here 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.
here is the script :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2024 02:09 PM
I can see that you raised separate post for this new issue/requirement, I will review there and provide my inputs. https://www.servicenow.com/community/app-engine-forum/dynamic-population-of-the-rows-via-email-scrip...
Please close this thread by marking relevant answer as correct.