Spacing issue on Notification email script

Ljone
Giga Contributor

Hi Experts,

Can someone please help me? 

I have a notification email script that queries and prints variables from RITM and field from REQEST table. Since there are lots of RITMS, the client wants to have the stamp bullet and list item, what I have so far is okay except for the Delivery address field in REQUEST table. This field is a string containing value sample below. When it is printed in notification the values are off in spacing. Please see last part for sample..  Can anyone  help me please!!

 

@Ankur Bawiskar  @Aman Kumar 

 

Sample value of field:

find_real_file.png

 

 

Notification Email script: (this is a shortened version of script)

    var item = new GlideRecord("sc_req_item");
    var cat = item.addQuery("cat_item.category", "d258b953c611227a0146101fb1be7c31"); // Hardware
    cat.addOrCondition("cat_item.category", "2c0b59874f7b4200086eeed18110c71f"); //Accessories
    item.addQuery("request", current.sys_id);
    item.query();
    template.print("Summary of Requested items:");

    while (item.next()) {
        var catalogItem = item.number + ': ' + item.cat_item.getDisplayValue();

            template.print("<ul>");  // stamp bullet
            template.print("<li>" + "Item: " + catalogItem) + "</li>";   //list item
            template.print('<br>' + "Model Number: " + item.cat_item.model.model_number + "<br />");
            template.print("Quantity: " + item.quantity + "<br />");
            template.print('</br>' + '<br />');
          
// this is where the issue is happening.. 
            template.print("Delivery Address: " + "<br />");
            template.print(item.request.delivery_address + "<br />");
            template.print('</br>' + '<br />');
 
        }
        template.print("</ul>");
    }
 
 
This is what it prints out in the Email in the Delivery address part, the last 4 lines are not aligned 
 
find_real_file.png
 
1 ACCEPTED SOLUTION

Kartik Sethi
Tera Guru
Tera Guru

Hi @Ljone 

 

You can try removing the newlines (\n,\r) and replacing them with break tags as provided below:

var deliveryAddress = item.request.delivery_address.trim();
deliveryAddress = deliveryAddress.replace(/(?:\r\n|\r|\n)/g, '<br>');

Please try and let me know if you face any issues.


Please mark my answer as correct if this solves your issues!

If it helped you in any way then please mark helpful!

 

Thanks and regards,

Kartik

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

can you try to trim the spaces?

Did you check how it looks when you print it in background script?

regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Kartik Sethi
Tera Guru
Tera Guru

Hi @Ljone 

 

You can try removing the newlines (\n,\r) and replacing them with break tags as provided below:

var deliveryAddress = item.request.delivery_address.trim();
deliveryAddress = deliveryAddress.replace(/(?:\r\n|\r|\n)/g, '<br>');

Please try and let me know if you face any issues.


Please mark my answer as correct if this solves your issues!

If it helped you in any way then please mark helpful!

 

Thanks and regards,

Kartik

Thank you Kartik,

This solved my issue! 🙂