- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2022 05:26 AM
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
And this is how it's showing in the notification
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!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2022 05:46 AM
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
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2022 05:46 AM
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
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2022 05:49 AM
Tested example :
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 :
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2022 06:33 AM
Thank you Abhijit - that's worked perfectly. Appreciate the help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2024 07:02 AM
Hi @Abhijit4 ,
i have tried same below script but it is showing only one comment, could you please help me