- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2023 01:49 AM
Hi Team,
I have a requirement to add the all inbound and outbound emails when user tries to sends email from email client for that I have created email client template in which where I was calling the email script to get all the emails for the particular record.
Email script code
var gr = new GlideRecord("sys_email");
gr.addQuery("instance",current.sys_id);
gr.orderBy("sys_created_on");
gr.query();
while(gr.next()){
template.print(gr.getValue('body'));
}
The above code brings all the emails and show on the email client but the issue is with alignment, it just copy paste the email body but no proper table format/breaks/lines are followed.
Is there away to show all the email is proper format?
Regrads,
Prudhvi
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2023 02:15 AM - edited ‎10-27-2023 02:16 AM
Hi @Prudhvi Raj4 ,
Within the script, you should iterate through the emails and transform line breaks into <br> tags. These <br> tags are essential in HTML for creating line breaks and formatting email content.
var gr = new GlideRecord("sys_email");
gr.addQuery("instance", current.sys_id);
gr.orderBy("sys_created_on");
gr.query();
var emailContent = "";
while (gr.next()) {
var emailBody = gr.getValue("body");
emailBody = emailBody.replace(/\n/g, "<br>");
emailContent += "<div style='border: 1px solid #ccc; padding: 10px; margin: 10px;'>" + emailBody + "</div>";
}
template.print(emailContent);
Please mark it as solution proposed and helpful if it works for you.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2023 02:14 AM
@Prudhvi Raj4 this may not be possible since your "body" field has the HTML data in it. Along with this, the outbound email sent contains Table/Images/Different size of Text.
Let me know if this helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2023 02:15 AM - edited ‎10-27-2023 02:16 AM
Hi @Prudhvi Raj4 ,
Within the script, you should iterate through the emails and transform line breaks into <br> tags. These <br> tags are essential in HTML for creating line breaks and formatting email content.
var gr = new GlideRecord("sys_email");
gr.addQuery("instance", current.sys_id);
gr.orderBy("sys_created_on");
gr.query();
var emailContent = "";
while (gr.next()) {
var emailBody = gr.getValue("body");
emailBody = emailBody.replace(/\n/g, "<br>");
emailContent += "<div style='border: 1px solid #ccc; padding: 10px; margin: 10px;'>" + emailBody + "</div>";
}
template.print(emailContent);
Please mark it as solution proposed and helpful if it works for you.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2023 03:40 AM
Hi @Prudhvi Raj4 ,
Please consider marking it as helpful for the benefit of future readers.
Thanks,
Anand