Issue with images attachment in email script

Jessica28
Tera Guru

Hello,

I attached 2 images in the Catalog Item.  However, when I receive the email, the images are showing side-by-side.

 

Jessica28_0-1699379912671.png

 

Is it possible to fix the following code to show images one on the top and other at the bottom?  Thank you

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {

var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', current.sys_id);
gr.addQuery('content_type', "CONTAINS", "image");
gr.query();
while (gr.next()) {
template.print("<img width='500' height='200' src=/sys_attachment.do?sys_id=" + gr.getValue('sys_id') + ">");
}

3 ACCEPTED SOLUTIONS

AshishKM
Kilo Patron
Kilo Patron

Hi @Jessica28 ,

Try to add line break tag inside the while.

while (gr.next()) {
template.print("<img width='500' height='200' src=/sys_attachment.do?sys_id=" + gr.getValue('sys_id') + ">");
template.print("<br>");
}

 

-Thanks

Ashish

Please accept solution and helpful for others if it helps you


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

View solution in original post

Azem
Tera Guru

Hi @Jessica28 ,

 

Hope all is well. Try adding a line break in the code and let me know your luck.

 

 

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {

var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', current.sys_id);
gr.addQuery('content_type', "CONTAINS", "image");
gr.query();
while (gr.next()) {
template.print("<img width='500' height='200' src=/sys_attachment.do?sys_id=" + gr.getValue('sys_id') + "><br>"); //add <br> between images
}

 

 

 

Kind regards,

View solution in original post

harshav
Tera Guru

Please update your script to something like this.

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {

var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', current.sys_id);
gr.addQuery('content_type', "CONTAINS", "image");
gr.query();
while (gr.next()) {
template.print("<div><img width='500' height='200' src=/sys_attachment.do?sys_id=" + gr.getValue('sys_id') + "></div><br/>");
}

View solution in original post

3 REPLIES 3

AshishKM
Kilo Patron
Kilo Patron

Hi @Jessica28 ,

Try to add line break tag inside the while.

while (gr.next()) {
template.print("<img width='500' height='200' src=/sys_attachment.do?sys_id=" + gr.getValue('sys_id') + ">");
template.print("<br>");
}

 

-Thanks

Ashish

Please accept solution and helpful for others if it helps you


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Azem
Tera Guru

Hi @Jessica28 ,

 

Hope all is well. Try adding a line break in the code and let me know your luck.

 

 

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {

var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', current.sys_id);
gr.addQuery('content_type', "CONTAINS", "image");
gr.query();
while (gr.next()) {
template.print("<img width='500' height='200' src=/sys_attachment.do?sys_id=" + gr.getValue('sys_id') + "><br>"); //add <br> between images
}

 

 

 

Kind regards,

harshav
Tera Guru

Please update your script to something like this.

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {

var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', current.sys_id);
gr.addQuery('content_type', "CONTAINS", "image");
gr.query();
while (gr.next()) {
template.print("<div><img width='500' height='200' src=/sys_attachment.do?sys_id=" + gr.getValue('sys_id') + "></div><br/>");
}