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 the out put using commas in background script

sekhar6
Tera Contributor

Hai all,

 I have a small doubt ,How to print the data using comma in the background script 

out put is

sekhar

chandu 

power

i want to print as 

sekhar,chandu,power.

 

 

thank you

sekhar.

 

14 REPLIES 14

Roshan Tiwari
Tera Guru

Hello @sekhar6 ,

 

Two ways to print output:

1: If you want to print hard code value use this:

gs.print("sekhar,chandu,power");

 

2: If you want to print variable values instead of sekhar,chandu,power use this:

gs.print(sekhar+","+chandu+","+power );

 

sekhar,chandu,power instead of these values you can apply your variable names.

hai 

i was using this script  

var arr= [];
var gr = new GlideRecord ('u_item_changes_volume');
gr.addQuery('901cf7a91bf715105d37fc8f034bcb3a');
gr.query();
while(gr.next()){
    var key = gr.u_location.trim();
    arr.push(key);
    }
var arrayUtil = new ArrayUtil();
arr = arrayUtil.unique(arr);
for (var i = 0; i < arr.length; i++ ) {
   // gr.split("[,]", 0);
gs.print (arr[i]);
//gs.update(current.u_specific_location);
}  
the out put is trigered as  shown below,

*** Script: Carlisle
*** Script: Harrisburg
*** Script: Ocala
*** Script: undefined
*** Script: Reno
*** Script: Fairfield

i want to print the data as

carlise,harrrisburg,ocala,reno,fairfield.

 

please help me

sekhar.

Try below:

 

var arr;
var gr = new GlideRecord ('u_item_changes_volume');
gr.addQuery('901cf7a91bf715105d37fc8f034bcb3a');
gr.query();
while(gr.next()){
   arr = gr.u_location.trim()+","+arr;
    }
gs.print (arr);

Raghav
MVP 2023
LinkedIn

sekhar6
Tera Contributor

Hai i want to print the out put on the parent record .

the parent field  back end value is "u_specific_location"

how to pust out put value in to the parent table field "u_specific_location"

 

var arr= [];
var gr = new GlideRecord ('u_item_changes_volume');
gr.addQuery('b25d9be21bfbd5105d37fc8f034bcb19');
gr.query();

while(gr.next()){
    var gv = gr.u_location.trim();
    arr.push(gv);
    }
var arrayUtil = new ArrayUtil();
arr = arrayUtil.unique(arr);
//gs.print (arr.join(","));  
 
 
I was  writing the code on the child table.
thank you.
Sekhar.