- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2022 11:08 PM
Hi,
I have created an email script to fetch the user's details added in watchlist of catalog item.
I am trying to display the result in a table structure. Kindly help me to do the same
expected result:
result of below code
cope snippet of mail script
// Get the list of users in the watchlist
var watchlist = current.watch_list.split(',');
// Create the email subject and body
var subject = current.number + ":" + " Watchlist Members Notification";
email.setSubject(subject);
var body = "This is a courtesy note to avoid CI incidents (reword). <br/><br/>";
template.print(body);
for (var i = 0; i < watchlist.length; i++) {
var user = new GlideRecord('sys_user');
user.get(watchlist[i]);
template.print('<style>');
template.print('table {border-collapse: collapse;border: 2px solid #ddd;text-align: left;}');
template.print('th, td {padding: 3px;border: 1px solid #ddd}');
template.print('tr:hover{background-color:#f5f5f5}');
template.print('</style>');
template.print('<table>');
template.print('<tr>');
template.print('<th>Name</th>');
template.print('<th>Email</th>');
template.print('<th>Location</th>');
template.print('<th>Title</th>');
template.print('</tr>');
template.print("<tr>");
//template.print("<tr ng-repeat=user in >");
template.print("<td>" + user.name + "</td>");
template.print("<td>" + user.email + "</td>");
template.print("<td>" + user.location.name + "</td>");
template.print("<td>" + user.title + "</td>");
template.print("</tr>");
template.print('</table>');
}
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 12:47 AM
Hey , try below code,
var watchlist = current.watch_list.split(',');
// Create the email subject and body
var subject = current.number + ":" + " Watchlist Members Notification";
email.setSubject(subject);
var body = "This is a courtesy note to avoid CI incidents (reword). <br/><br/>";
template.print(body);
template.print('<style>');
template.print('table {border-collapse: collapse;border: 2px solid #ddd;text-align: left;}');
template.print('th, td {padding: 3px;border: 1px solid #ddd}');
template.print('tr:hover{background-color:#f5f5f5}');
template.print('</style>');
template.print('<table>');
template.print('<tr>');
template.print('<th>Name</th>');
template.print('<th>Email</th>');
template.print('<th>Location</th>');
template.print('<th>Title</th>');
template.print('</tr>');
for (var i = 0; i < watchlist.length; i++) {
var user = new GlideRecord('sys_user');
user.get(watchlist[i]);
template.print("<tr>");
//template.print("<tr ng-repeat=user in >");
template.print("<td>" + user.name + "</td>");
template.print("<td>" + user.email + "</td>");
template.print("<td>" + user.location.name + "</td>");
template.print("<td>" + user.title + "</td>");
template.print("</tr>");
}
template.print('</table>');
If this helps, please mark the answer correct/helpful.
Regards,
Prashanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 12:47 AM
Hey , try below code,
var watchlist = current.watch_list.split(',');
// Create the email subject and body
var subject = current.number + ":" + " Watchlist Members Notification";
email.setSubject(subject);
var body = "This is a courtesy note to avoid CI incidents (reword). <br/><br/>";
template.print(body);
template.print('<style>');
template.print('table {border-collapse: collapse;border: 2px solid #ddd;text-align: left;}');
template.print('th, td {padding: 3px;border: 1px solid #ddd}');
template.print('tr:hover{background-color:#f5f5f5}');
template.print('</style>');
template.print('<table>');
template.print('<tr>');
template.print('<th>Name</th>');
template.print('<th>Email</th>');
template.print('<th>Location</th>');
template.print('<th>Title</th>');
template.print('</tr>');
for (var i = 0; i < watchlist.length; i++) {
var user = new GlideRecord('sys_user');
user.get(watchlist[i]);
template.print("<tr>");
//template.print("<tr ng-repeat=user in >");
template.print("<td>" + user.name + "</td>");
template.print("<td>" + user.email + "</td>");
template.print("<td>" + user.location.name + "</td>");
template.print("<td>" + user.title + "</td>");
template.print("</tr>");
}
template.print('</table>');
If this helps, please mark the answer correct/helpful.
Regards,
Prashanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 12:51 AM
Hi @Bindhu1,
Your table header should be out side of loop.
Try this updated scripts -
Get the list of users in the watchlist
var watchlist = current.watch_list.split(',');
// Create the email subject and body
var subject = current.number + ":" + " Watchlist Members Notification";
email.setSubject(subject);
var body = "This is a courtesy note to avoid CI incidents (reword). <br/><br/>";
template.print(body);
template.print('<style>');
template.print('table {border-collapse: collapse;border: 2px solid #ddd;text-align: left;}');
template.print('th, td {padding: 3px;border: 1px solid #ddd}');
template.print('tr:hover{background-color:#f5f5f5}');
template.print('</style>');
template.print('<table>');
template.print('<tr>');
template.print('<th>Name</th>');
template.print('<th>Email</th>');
template.print('<th>Location</th>');
template.print('<th>Title</th>');
template.print('</tr>');
for (var i = 0; i < watchlist.length; i++) {
var user = new GlideRecord('sys_user');
user.get(watchlist[i]);
template.print("<tr>");
//template.print("<tr ng-repeat=user in >");
template.print("<td>" + user.name + "</td>");
template.print("<td>" + user.email + "</td>");
template.print("<td>" + user.location.name + "</td>");
template.print("<td>" + user.title + "</td>");
template.print("</tr>");
template.print('</table>');
}
Thanks,
Sagar Pagar