pass output in array
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 06:02 AM
Hi All,
How to pass the output of the script in an array?
Output is:
Group1
Group2
Group3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 11:47 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 01:02 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 01:14 AM
please share what's your exact business requirement and the script you are using now
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 01:32 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 02:28 AM