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.

How to make array values line by line while using in notification?

KM SN
Tera Expert

I am triggering notification through event where I am passing  array as PARAM but they were coming as one after one in notification but expectation is one in one line. I tried with below code but not working? 

 

var multiplePersona = [];
    var persona = new GlideRecord("u_user_persona");
    persona.addQuery("u_sub_practice", 'CONTAINS', current.sys_id);
    persona.query();
    while (persona.next()) {
       
        multiplePersona.push(persona.getValue('u_name').toString());
    }
   // gs.log('user persona list ' + multiplePersona);

        var valueString = multiplePersona.join("\n");
        gs.log('user persona list ' + valueString);
        gs.eventQueue("user.persona.changed", current, valueString);
1 ACCEPTED SOLUTION

Pass it as a comma spirited array when you call the event. Then use a mail script to print them in the email line by line. In your notification it to call a mail script your do ${mail_script:scriptname}

Your mail script should look something like this. This is based off your current code already having the display value rather then the sys_id.

 

 

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

    // Add your code here
    var Persona = event.parm1.toString().splite(",");
    for (var i = 0; i < Persona.length; i++) {
        template.print(Persona[i] + "</br>"); //use /br instead of \n becasue it is a new line in HTML in a notification
    }

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

 

 

View solution in original post

7 REPLIES 7

Brian Lancaster
Kilo Patron

Is it that you are trying to print a list of persona's in a notification but instead of a comma separated list you want to show the 1 persona per line?

Exactly @Brian Lancaster  that's what I am trying for.

 

Pass it as a comma spirited array when you call the event. Then use a mail script to print them in the email line by line. In your notification it to call a mail script your do ${mail_script:scriptname}

Your mail script should look something like this. This is based off your current code already having the display value rather then the sys_id.

 

 

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

    // Add your code here
    var Persona = event.parm1.toString().splite(",");
    for (var i = 0; i < Persona.length; i++) {
        template.print(Persona[i] + "</br>"); //use /br instead of \n becasue it is a new line in HTML in a notification
    }

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

 

 

Sandeep Rajput
Tera Patron
Tera Patron

@KM SN Ideally, you should handle this inside the email script and not via the script from where the event is triggered.