how to print an individual array element to Email Notification using Email Script

Shailja Dosar
Tera Contributor

Hello Team,

I am trying to display a list of accessories, ordered via a Record Producer, in an email notification. My goal is to present the list in a bulleted format. To achieve this, I have written an email script; however, the output appears in a single line instead of separate bullet points.

Below, I have included the snippet of my email script along with the email notification preview for reference.

Could you please guide me on how to achieve the desired bulleted format? Any assistance would be greatly appreciated.

Thank you in advance for your help!

shailjad_0-1734432591194.pngshailjad_1-1734432833716.png

 

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@Shailja Dosar 

you should use this

template.print('<ul>');
for(var i=0; i< numSel; i++){
template.print('<li>' + result[i] + '</li>');
}
template.print('</ul>');

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

Runjay Patel
Giga Sage

Hi @Shailja Dosar ,

 

You adjust your code like below.

if (numSel.length() > 0) {
     
        var output = '<ul>';
        for (var i = 0; i < numSel; i++) {
            output += '<li>' + result[i] + '</li>';
        }
        output += '</ul>';

        // Output the list
        template.print(output);
    } else {
        template.print('No accessories ordered.');
    }

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Shailja Dosar 

you should use this

template.print('<ul>');
for(var i=0; i< numSel; i++){
template.print('<li>' + result[i] + '</li>');
}
template.print('</ul>');

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Runjay Patel
Giga Sage

Hi @Shailja Dosar ,

 

You adjust your code like below.

if (numSel.length() > 0) {
     
        var output = '<ul>';
        for (var i = 0; i < numSel; i++) {
            output += '<li>' + result[i] + '</li>';
        }
        output += '</ul>';

        // Output the list
        template.print(output);
    } else {
        template.print('No accessories ordered.');
    }

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

Hi @Shailja Dosar ,

 

Thank you for marking my solution as helpful! The community now supports multi-solution acceptance, allowing you to accept multiple answers.