Record Produce field should updated in backend table details section in table and column format
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2025 06:20 AM
Requirement- Record produce all variable data should get updated in table details section.
Issue - I have created script and it is working fine for all variable but there is one MRVS type variable set so MRVS data is not getting captured.
Script I implemented-
current.short_description = "Visitor Request For " + producer.xyz_location.getDisplayValue() + " - " + producer.start;
current.u_request_type = 'visitor request';
var detailsTable = "<table border='1' style='width:100%; border-collapse: collapse;'>";
detailsTable += "<tr><th style='padding: 5px; text-align: left;'>Field</th><th style='padding: 5px; text-align: left;'>Value</th></tr>";
detailsTable += "<tr><td>Requested By</td><td>" + producer.requested_by.getDisplayValue() + "</td></tr>";
detailsTable += "<tr><td>xyz Host (if different)</td><td>" + producer.xyz_host.getDisplayValue() + "</td></tr>";
detailsTable += "<tr><td> XYZ Location</td><td>" + producer.xyz_location.getDisplayValue() + "</td></tr>";
detailsTable += "<tr><td>Start</td><td>" + producer.start + "</td></tr>";
detailsTable += "<tr><td>End</td><td>" + producer.end + "</td></tr>";
detailsTable += "<tr><td>Purpose of Visit</td><td>" + producer.Purp_of_visit + "</td></tr>";
detailsTable += "</table>";
// Handling Multi-Row Variable Set (Visitor Details)
var visitorTable = "<br><b>Visitor Details:</b><br>";
visitorTable += "<table border='1' style='width:100%; border-collapse: collapse;'>";
visitorTable += "<tr><th style='padding: 5px; text-align: left;'>First Name</th><th style='padding: 5px; text-align: left;'>Last Name</th><th style='padding: 5px; text-align: left;'>Email</th><th style='padding: 5px; text-align: left;'>Company</th><th style='padding: 5px; text-align: left;'>Phone</th></tr>";
// Check if visitor_details has any rows
var visitorRows = producer.visitor_details;
if (visitorRows && visitorRows.getRowCount() > 0) { // Check row count
for (var i = 0; i < visitorRows.getRowCount(); i++) {
var row = visitorRows.getRow(i); // Get row
visitorTable += "<tr>";
visitorTable += "<td>" + row.first_name.getValue() + "</td>";
visitorTable += "<td>" + row.last_name.getValue() + "</td>";
visitorTable += "<td>" + row.email.getValue() + "</td>";
visitorTable += "<td>" + row.company.getValue() + "</td>";
visitorTable += "<td>" + row.phone.getValue() + "</td>";
visitorTable += "</tr>";
}
} else {
visitorTable += "<tr><td colspan='5' style='text-align: center;'>No visitors provided</td></tr>";
}
visitorTable += "</table>";
current.details = detailsTable + visitorTable;
Please correct me where I am doing Mistake
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2025 06:25 AM
try this
current.short_description = "Visitor Request For " + producer.xyz_location.getDisplayValue() + " - " + producer.start;
current.u_request_type = 'visitor request';
var detailsTable = "<table border='1' style='width:100%; border-collapse: collapse;'>";
detailsTable += "<tr><th style='padding: 5px; text-align: left;'>Field</th><th style='padding: 5px; text-align: left;'>Value</th></tr>";
detailsTable += "<tr><td>Requested By</td><td>" + producer.requested_by.getDisplayValue() + "</td></tr>";
detailsTable += "<tr><td>xyz Host (if different)</td><td>" + producer.xyz_host.getDisplayValue() + "</td></tr>";
detailsTable += "<tr><td> XYZ Location</td><td>" + producer.xyz_location.getDisplayValue() + "</td></tr>";
detailsTable += "<tr><td>Start</td><td>" + producer.start + "</td></tr>";
detailsTable += "<tr><td>End</td><td>" + producer.end + "</td></tr>";
detailsTable += "<tr><td>Purpose of Visit</td><td>" + producer.Purp_of_visit + "</td></tr>";
detailsTable += "</table>";
// Handling Multi-Row Variable Set (Visitor Details)
var visitorTable = "<br><b>Visitor Details:</b><br>";
visitorTable += "<table border='1' style='width:100%; border-collapse: collapse;'>";
visitorTable += "<tr><th style='padding: 5px; text-align: left;'>First Name</th><th style='padding: 5px; text-align: left;'>Last Name</th><th style='padding: 5px; text-align: left;'>Email</th><th style='padding: 5px; text-align: left;'>Company</th><th style='padding: 5px; text-align: left;'>Phone</th></tr>";
// Check if visitor_details has any rows
var visitorRows = producer.variables.visitor_details; // Ensure correct reference to MRVS
if (visitorRows && visitorRows.length > 0) { // Check row count
for (var i = 0; i < visitorRows.length; i++) {
var row = visitorRows[i]; // Get row
visitorTable += "<tr>";
visitorTable += "<td>" + row.first_name + "</td>";
visitorTable += "<td>" + row.last_name + "</td>";
visitorTable += "<td>" + row.email + "</td>";
visitorTable += "<td>" + row.company + "</td>";
visitorTable += "<td>" + row.phone + "</td>";
visitorTable += "</tr>";
}
} else {
visitorTable += "<tr><td colspan='5' style='text-align: center;'>No visitors provided</td></tr>";
}
visitorTable += "</table>";
current.details = detailsTable + visitorTable;
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2025 06:44 AM
It is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2025 08:05 PM
what debugging did you perform?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader