Email Notification Template's mail_script not called when a RegEx used

steve_gannon
Tera Expert
Spoiler
 

I am encountering a problem with our email notification template that utilizes a mail_script. Specifically, the email_script is designed to return a journal entry as part of the notification content. However, we are facing an issue where the journal entry retrieved includes erroneous code bookending the required text, such as "[code] Keep this text [/code]." 

 

To address this issue, I attempted to use a Regular Expression within the mail_script to remove the code snippets from the journal entry. The Regex pattern we used is as follows:

 

 

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

 

 

The goal is to have a clean journal entry without any "[code]" or "[/code]" tags.

 

Problem: The problem we are facing is that when the Regex is used in the mail_script, the mail_script itself is not being executed. Consequently, the HTML table and other essential information are not available in the email notification.

Additional Information:

  • The context for this issue is within a notification template named "Issue Rejected."

Screenshots: [Please find attached screenshots that illustrate the issue for your reference.]

 

Mail Script:

 

(function runMailScript(current, template, email, email_action, event) {
    //var link = current.getLink();
    var link = gs.getProperty('glide.servlet.uri') + 'x/####/workspace/####/record/sn_grc_issue/' + current.sysapproval;
    var notes = current.comments.getJournalEntry(1); // This entry pulls code snippet from the Jornal field
    //var notes =  current.comments.getJournalEntry(1).split('\n')[1].replace(/\[code\]|\[\/code\]/g,"");  // This entry removes code snippet from the Jornal field
    var Content = notes.split("(Comments)\n");
    var lastComment = Content[1].toString();
    var str_text = '<table class="MsoTableGridLight"; style="width: 450.0pt; border-collapse: collapse; border: none;" border="1" cellspacing="0" cellpadding="0">';
    str_text += '<tbody><tr>';
    // Ref Link
    str_text += '<td style="width: 30%; vertical-align: top; padding-left: 20px;"><span style="font-family: Calibri, sans-serif; font-size: 11pt;"><strong>Ref Number</strong></span></td>';
    str_text += '<td style="width: 70%; vertical-align: top; padding-left: 5px;"><span style="font-family: Calibri, sans-serif; font-size: 11pt;"> <a href= "' + link + '">' + current.sysapproval.number + '</a></span></td></tr>';
    //Name of action
    str_text += '<tr><td style="width: 30%; vertical-align: top; padding-left: 20px;"><span style="font-family: Calibri, sans-serif; font-size: 11pt;"><strong>Name</strong></span></td>';
    str_text += '<td style="width: 70%; vertical-align: top; padding-left: 5px;"><span style="font-family: Calibri, sans-serif; font-size: 11pt;">' + current.sysapproval.short_description + '</span></td></tr>';
    //Assigned to
    str_text += '<tr><td style="width: 30%; vertical-align: top;padding-left: 20px;"><span style="font-family: Calibri, sans-serif; font-size: 11pt;"><strong>Assigned to</strong></span></td>';
    str_text += '<td style="width: 70%; vertical-align: top; padding-left: 5px;"><span style="font-family: Calibri, sans-serif; font-size: 11pt;">' + current.sysapproval.assigned_to.name + '</span></td></tr>';
    //Comment
    str_text += '<tr><td style="width: 30%; vertical-align: top; padding-left: 20px;"><span style="font-family: Calibri, sans-serif; font-size: 11pt;"><strong>Comment</strong></span></td>';
    str_text += '<td style="width: 70%; vertical-align: top; padding-left: 5px;"><span style="font-family: Calibri, sans-serif; font-size: 11pt;">' + lastComment + '</span></td></tr>';
    str_text += '</tbody></table>';
    template.print(str_text);
})(current, template, email, email_action, event);

 

 

3 REPLIES 3

steve_gannon
Tera Expert

Update: the mail_script is being called but can't be parsed as the issue with my RegEx and reading the journal filed data.

 

SMG_Duplicate
Tera Contributor

Hi, This is working as expected now after debugging pointed to the ‘replace’ function not being defined.

I removed  ‘.split('\n')[1]’ and used

"var notes =  current.comments.getJournalEntry(1).replace(/\[code\]|\[\/code\]/g,"");” which worked.

If any knows why .split was the issue please share.

 

Using "var lastComment = Content[1].toString();" only the comments were returned"

SMG_Duplicate_0-1696498416601.png

And 

var lastComment = Content; //Comments and Timestamp/Approver name returned

SMG_Duplicate_1-1696498819331.png

 

SMG_Duplicate
Tera Contributor

Solved 

Debugging pointed to the ‘replace’ function not being defined.

I removed  ‘.split('\n')[1]’

So “    var notes =  current.comments.getJournalEntry(1).replace(/\[code\]|\[\/code\]/g,"");” worked, though if someone can explain why .split was the issue that would be great.

 

I used var lastComment = Content[1].toString();

Which returned the Comments.

SMG_Duplicate_0-1696500535915.png

 

Using var lastComment = Content; would have returned Comments and Timestamp/Approver name

SMG_Duplicate_1-1696500567958.png