Email Script: Formatting of Lines in a string so each line has a bullet

DarkWingII
Tera Contributor

Hi All

I have an email script that pulls in the data from a field, and as long as the data is one long string of text the formatting is right.

i have selected Newlines to HTML so every line in the string is a new line.

this does make every line to a new line, but these lines have no formatting and
i would like each new line to be formatted the same, in this case indented with a bullet

this is the base script:

 

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

// Add your code here
if (current.u_what_is_happening_pt3 != '') {
template.print('<ul><li>' + current.u_what_is_happening_pt3.getDisplayValue() + '</li></ul>');
}
})(current, template, email, email_action, event);

this is the field with text

DarkWingII_1-1666793861256.png

this is what appears on the email

DarkWingII_0-1666793762491.png

and this is what i get when previewing, which is better because it looks indented

DarkWingII_2-1666793934577.png

Any help would be appreciated

1 ACCEPTED SOLUTION

Sagar Pagar
Tera Patron

Hi @DarkWingII,

 

Try this updated scripts in Email scritps -

 

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

	// Add your code here

	var str = [];
	if (current.u_what_is_happening_pt3 != '') {
		str = current.u_what_is_happening_pt3.toString().split("\n");
	}

	for (var i = 0; i < str.length; i++) {
		template.print('<ul><li>' + str[i] + '</li></ul>');
	}
})(current, template, email, email_action, event);

 

Thanks!

Sagar Pagar

The world works with ServiceNow

View solution in original post

2 REPLIES 2

Sagar Pagar
Tera Patron

Hi @DarkWingII,

 

Try this updated scripts in Email scritps -

 

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

	// Add your code here

	var str = [];
	if (current.u_what_is_happening_pt3 != '') {
		str = current.u_what_is_happening_pt3.toString().split("\n");
	}

	for (var i = 0; i < str.length; i++) {
		template.print('<ul><li>' + str[i] + '</li></ul>');
	}
})(current, template, email, email_action, event);

 

Thanks!

Sagar Pagar

The world works with ServiceNow

Thank you that works a treat!