pass output in array

Rakshanda Kunte
Tera Contributor

Hi All,

How to pass the output of the script in an array?

 

 

Output is:

Group1

Group2

Group3

9 REPLIES 9

Hi @Rakshanda Kunte ,

No you can use array to store all your groups

var groupArray = [];

for (var i = 1; i <= 521; i++) {
    groupArray.push("Group" + i);
}

gs.print("Array Contents: " + groupArray.join(', '));

Please mark it as helpful and solution proposed if it serves your purpose.

Thanks,

Anand

Hi @Anand Kumar P

 

My output is:

FamilyABC

FamilyDEF

FamilyGHI

.

.

.

.

.

FamilyJK (such 521 rows)

 

I tried above script it gave me below o/p:

*** Script: Array Contents: Group1, Group2, Group3, ............. Group521

I need names of group instead of "Group1, Group2, Group3, ............. Group521".

 

Would you please help?

 

 

Thanks.

Ankur Bawiskar
Tera Patron
Tera Patron

@Rakshanda Kunte 

please share what's your exact business requirement and the script you are using now

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar ,

Below is my script:

 

var gr = new GlideRecord ('department');
gr.query();
var groupData ={};
while (gr.next())
{
var array = gr.rel.level_4.name;    //(getting family names)
if (!groupData[array]){
groupData[array]=[];
}
}
for (var key in groupData){
gs.print ('Family' + ' ' + key);                (printing family names)

}

 

Output looks as below:

*** Script: Family Tech
*** Script: Family CB Eur
*** Script: Family PM Tech
*** Script: Family Demo
*** Script: Family Sample Family
.
.
.
.
.
*** Script: Family PM Demo (till 521 rows)

 

I need to get this data in an array. 

 

 

I have more requirements after this, but going step by step.

Hi @Ankur Bawiskar ,

 

Kindly, let me know if there is any way to pass these in an array.

 

 

Thanks..