Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Remove Lines for comments in email script

Harika Thota
Tera Expert

Hi,

 

I have a requirement to remove lines for every comment in email script. 

HarikaThota_0-1748454258445.png

Thanks in Advance,

Harika

1 ACCEPTED SOLUTION

Hey Harika,

 

Replace:

html += '<p><strong>' + createdOn + ' - ' + author + '</strong><br>' + comment + '</p>';

with: 

html += '<p><strong>' + createdOn + ' - ' + author + ' – Additional comments</strong><br>' + comment + '</p>';

 

Could you also mark my response with correct and helpful?

Thanks in advance! 

View solution in original post

5 REPLIES 5

Hristo Ivanov
Kilo Sage
Kilo Sage

can you share the email script? 

(function runMailScript(current, template, email, email_action, event) {
	
template.print('<p><font size="2" face="verdana">' + gs.getMessage('${comments}') + '</font></p>');
		
})(current, template, email, email_action, event);

To remove the lines between comments in your email output, you need to customize how the journal field (comments or work_notes) is rendered in the email.

The default rendering includes a horizontal rule (<hr>) or styled separator — that’s what’s creating the lines. In order to get rid of them you have to build the HTML yourself, instead of using ${comments} which includes those lines.

 

Something along those lines should do the trick, please check and adjust:

(function runMailScript(current, template, email, email_action, event) {

    var journalFieldName = 'comments'; // use 'work_notes' if needed
    var gr = new GlideRecord('sys_journal_field');
    gr.addQuery('element_id', current.sys_id);
    gr.addQuery('element', journalFieldName);
    gr.orderByDesc('sys_created_on');
    gr.query();

    var html = '<div style="font-family: Verdana; font-size: 12px;">';
    while (gr.next()) {
        var createdOn = gr.getValue('sys_created_on');
        var author = gr.getDisplayValue('sys_created_by');
        var comment = gr.getDisplayValue('value');

        html += '<p><strong>' + createdOn + ' - ' + author + '</strong><br>' + comment + '</p>';
    }
    html += '</div>';

    template.print(html);

})(current, template, email, email_action, event);

Please mark this response as correct and helpful if it helps you

Hi Hristo,

 

This code works. but what if i want to add Additional comments text at end of line?

 

Thanks,

Harika