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

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

Raghav
MVP 2023

@sekhar6 , use join method.

 

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);
gs.print (arr.join(","));
 

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.

@sekhar6 gr.addQuery('901cf7a91bf715105d37fc8f034bcb3a');

 

This line is wrong.

 

you must have some field in addQuery function. its just sys_id.

 

AND

after the below line just add print statement dont need for loop

arr = arrayUtil.unique(arr);

gs.print(arr.toString())

 

Please mark as helpful based on impact

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

hai ,

 i was using this script because to clear the duplicate values and print he data

 

var arr= [];
var gr = new GlideRecord ('u_item_changes_volume');
gr.addQuery('u_event',current.sys_id);
gr.query();

while(gr.next()){
var gv = gr.u_location.trim();
arr.push(gv);
}
var arrayUtil = new ArrayUtil();
arr = arrayUtil.unique(arr);
arr.push("u_specific_location");
current.u_specific_location =(arr.join(","));
//gs.print (arr.join(","));

 i have written this on the child table business rule ,  the script is working fine ,my target is to push the out put data in to the parent record field ,

help me on this,

thank you,

sekhar.