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

I am not sure how to proceed.

here if I observed a change in Table A record based on it I am fetching the records of Table B  where the modified Table A  record is part. 

If don't use BR how do I trigger notification based on Table A record change?
let me know if you have any idea over it.

Ravi Gaurav
Giga Sage

Hello @KM SN 

 

I guess you achieve your expected result, by passing the concatenated string to the event queue instead of the array. Here's the modified code:

 

Please try this :- 

 

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());
}
var valueString = multiplePersona.join(", "); // use comma and space instead of newline
gs.log('user persona list ' + valueString);
gs.eventQueue("user.persona.changed", current, valueString);

 

But the client expecting it be one after another but not coma separated.  don't we get one by one as shown below

**********
**********
**********