Remove [code] [/code] from Email notification

Hari7
Kilo Guru

I am trying to remove the assignee name from the email notification and I have created an email script as below. When I test the notification, I am getting [code] [/code] in the email notification and not finding a way to get this removed. 

Email 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(comment);	

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

Notification:

find_real_file.png

1 ACCEPTED SOLUTION

Hi @Hari 

Try at the end of the line where "comment" is being assigned:

var comment = current.comments.getJournalEntry(1).split('\n')[1].replace(/(\[.?*\])/g,"");

or

var comment = current.comments.getJournalEntry(1).split('\n')[1].replace(/\[code\]|\[\/code\]/g,"");

View solution in original post

8 REPLIES 8

Hi @subrahmanyam 

Have you tried using the .replace() method on it?

// find the pattern of  square brackets and anything inside them globally and replace with an empty string
var noCodeTags = internalComments.replace(/(\[.*?\])/g, "");

or an exact

//find the pattern "[code]" or "[/code]" and replace with empty string
var noCodeTags = internalComments.replace(/\[code\]|\[\/code\]/g, "");

 

That should work if the value from comments is an actual string.

Pls let me know where do you want to add this code in the below email 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(comment);

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

Hi @Hari 

Try at the end of the line where "comment" is being assigned:

var comment = current.comments.getJournalEntry(1).split('\n')[1].replace(/(\[.?*\])/g,"");

or

var comment = current.comments.getJournalEntry(1).split('\n')[1].replace(/\[code\]|\[\/code\]/g,"");

Thank you @ChrisBurks . The below code worked fine.

var comment = current.comments.getJournalEntry(1).split('\n')[1].replace(/\[code\]|\[\/code\]/g,"");