Custom mail script not displaying full journal entry

LRhodes
Tera Guru

Hi all,

I have a custom mail script which was created to essentially remove the users name who added the additional comments from the email being sent to the end user.

This works fine, however the problem we have now is that if the additional comment is over multiple lines then only the first line is included in the email.

Mail script:

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {
	
			var date = current.comments.getJournalEntry(1).split('\n')[0].split(' - ')[0];
			var comment = current.comments.getJournalEntry(1).split('\n')[1];
				template.print(date);
				template.print('\n');
				template.print(comment);

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

Additional comment added

find_real_file.png

And this is how it's showing in the notification

find_real_file.png

I'm at a loss as to what I need to do but I'm sure it's something to do with "current.comments.getJournalEntry(1).split('\n')[1];" splitting as soon as there is another new line.

Thanks in advance for any assistance!

1 ACCEPTED SOLUTION

Abhijit4
Mega Sage

Hi,

Based on your requirement I have modified script, please try below.

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {
	
			var date = current.comments.getJournalEntry(1).split('\n')[0].split(' - ')[0];
var commentWholeText=current.comments.getJournalEntry(1);
			var comment = current.comments.getJournalEntry(1).substring(commentWholeText.indexOf('\n')+1);
				template.print(date);
				template.print('\n');
				template.print(comment);

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

I have tested the same in PDI.

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

View solution in original post

4 REPLIES 4

Abhijit4
Mega Sage

Hi,

Based on your requirement I have modified script, please try below.

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {
	
			var date = current.comments.getJournalEntry(1).split('\n')[0].split(' - ')[0];
var commentWholeText=current.comments.getJournalEntry(1);
			var comment = current.comments.getJournalEntry(1).substring(commentWholeText.indexOf('\n')+1);
				template.print(date);
				template.print('\n');
				template.print(comment);

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

I have tested the same in PDI.

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Tested example :

find_real_file.png

Script :

var current=new GlideRecord("problem");
if(current.get("62304320731823002728660c4cf6a7e8")){
var text=current.work_notes.getJournalEntry(1);
var date = current.work_notes.getJournalEntry(1).split('\n')[0].split(' - ')[0];
var comment = current.work_notes.getJournalEntry(1).substring(text.indexOf('\n')+1);
gs.print(date);
gs.print(comment);
}

 

Output :

find_real_file.png

 

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Thank you Abhijit - that's worked perfectly. Appreciate the help!

slimgam
Tera Contributor

Hi @Abhijit4 ,

i have tried same below script but it is showing only one comment, could you please help me

 

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

    var date = current.u_comments_to_customer.getJournalEntry(1).split('\n')[0].split(' - ')[0];
    var commentWholeText = current.u_comments_to_customer.getJournalEntry(1);
    var comment = current.u_comments_to_customer.getJournalEntry(1).substring(commentWholeText.indexOf('\n') +1);
    template.print(date);
    template.print('\n');
    template.print(comment);

})(current, template, email, email_action, event);
 
slimgam_0-1715349739890.png