notification email script using array

kalay
Kilo Contributor

Hello,

We are struggling on how to show in email notification the list of systems impacted.

Here's how it shows in Change request table (they are comma separated since this is from list type of field).

change_table.png

So we thought of using array in our script...apparently it's not working for us.

template.print("Summary of Change:\n\n");  

  var gr = new GlideRecord("change_request");

  gr.addQuery("sys_id", current.sysapproval);

  gr.query();

  while(gr.next()) {

    template.print("1. Business and/or Technical Reasons: " +gr.u_bustechreason+ "\n");

    template.print("2. Implementation Start Date/Time : " +gr.start_date+ "\n");

    template.print("     Implementation End Date/Time : " +gr.end_date+ "\n");

    template.print("3. System : " +gr.u_system.u_name+ "\n");

        var list = gr.u_impacted_system.toString();

        var array = list.split(",");

        for (var i=0; i < array.length; i++) {

  template.print("Impacted System : " +array[i].gr.u_impacted_system.u_name + "\n");

                }    

}

Appreciate any thoughts on how to display these Impacted system in our email notification.

2 REPLIES 2

manikorada
ServiceNow Employee
ServiceNow Employee

Change your code like this:



var list = gr.u_impacted_system.getDisplayValue();


        var array = list.split(",");


        for (var i=0; i < array.length; i++) {


  template.print("Impacted System : " +array[i] + "\n");


                }  


kalay
Kilo Contributor

Thank You Mani this one works !!!!