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.

Email Notification is going out with 'Code' text

Alon Grod
Tera Expert

Hi, 

Im having a problem that my notification is going out with the word 'Code' at the top and at the bottom. it happens only when I add comments or work_notes in the service operation workspace (I think its because the comments and workontes in the workspace are HTML).

This is my script: 

function runMailScript( /* GlideRecord */ current, / TemplatePrinter */ template, /Optional Emailoutbound */

email, / Optional GlideRecord / email_action,

- /* Optional GlideRecord */

 event) {

var commentorName event.parm2;

var userGr= new GlideRecord('sys_user 8 userGr.addQuery('sys_id, commentorName);

');

userGr.query();

if (userGr.next()) {

commentorName= userGr.name;

var user_name = userGr.user_name.toString();

 }




var gr new GlideRecord('sys_journal_field");

gr.addEncodedQuery("sys_created_by=+ user_name); gr.orderByDesc("sys_created on) ;

gr.query();

if (gr.next()) { var comment gr.value.toString();

template.print(commentorName+":"+comment + "\"");

(current, template, email, email action, event);

 

The email output (ttt is the comment message):

 

WhatsApp Image 2023-08-14 at 11.44.44.jpeg

7 REPLIES 7

Maik Skoddow
Tera Patron
Tera Patron

Hi

due to security reasons HTML in the journal fields like work notes or additional comments are enclosed in 

[code] ... [/code] blocks.

These starting and ending "tags" have to be removed first before inserting the content into the email.

Maik 

@Maik Skoddow hi, how can I remove them using the code?

Ajay_Chavan
Kilo Sage

try this: 

function runMailScript(current, template, email, email_action, event) {
  var commentorName = event.parm2;

  var userGr = new GlideRecord('sys_user');
  userGr.addQuery('sys_id', commentorName);
  userGr.query();

  if (userGr.next()) {
    commentorName = userGr.name;
    var user_name = userGr.user_name.toString();
  }

  var gr = new GlideRecord('sys_journal_field');
  gr.addEncodedQuery('sys_created_by=' + user_name);
  gr.orderByDesc('sys_created_on');
  gr.query();

  if (gr.next()) {
    var comment = gr.value.toString();
    template.print(commentorName + ': ' + comment + '"');
    // Add your email processing logic here if needed.
  }
}
Glad I could help! If this solved your issue, please mark it as Helpful and Accept as Solution so others can benefit too.*****Chavan A.P. | Technical Architect | Certified Professional*****