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 print an array

rjp
Tera Expert

Hi folks,

Currently my array prints like this

find_real_file.png

using this statement..

template.print(newRes.toString().split('<br />'));

 

I need to have it printed in a column, separated by a newline, like this...

Brian Forbes

Chhorda Rorth

etc

 

Is it possible to do this?

Thanks,

Rob

 

1 ACCEPTED SOLUTION

Mike Patel
Tera Sage

try changing

template.print(newRes.toString().split('<br />'));

to

template.print(newRes.toString().split(',').join('<br />'));

View solution in original post

3 REPLIES 3

Mwatkins
ServiceNow Employee
ServiceNow Employee

Assuming you replace headers and field names with the ones you want, something to the effect of...

var myhtml="<html><body><table><th>Configuration Item</th><th> u_environment</th><th> u_affected_business_units </th><th> u_lifecycle_state </th><tr>";

for(i=0;i<arr.length;i++) {
  switch(i) {
    case 0: {
      myhtml = myhtml + "<td>"+arr[i].configuration_item+"</td><td>"+arr[i].state+"</td>"; 
      break;
    }
    case 1:{
      myhtml = myhtml + "<td>"+arr[i].state+"</td>";
      break;
    }
    case 2: {
      myhtml = myhtml + "<td>"+arr[i].state+"</td>";
      break;
    }
  }
}
myhtml = myhtml+"</tr></table></body></html>";
template.print(myhtml);

Please Correct if this solves your issue and/or  👍 if Helpful

Mike Patel
Tera Sage

try changing

template.print(newRes.toString().split('<br />'));

to

template.print(newRes.toString().split(',').join('<br />'));

rjp
Tera Expert

THank you both for all of your guidance with this solution.  Your generosity with all your knowledge and expertise is an inspiration.

THank you!