- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2019 10:22 AM
Hi,
Currnetly i am getting an output as output = abcd, efgh, ijkl
which i want to convert as ["abcd","efgh", "ijkl"]
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2019 10:36 AM
var inputStr = 'abcd,efgh,ijkl';
var outputStr = inputStr.split(',');
var strArr = [];
for(var i = 0; i < outputStr.length; i++) {
strArr.push('"' + outputStr[i] + '"');
}
strArr.join();
gs.info(inputStr);
gs.info(strArr);
*** Script: abcd,efgh,ijkl
*** Script: "abcd","efgh","ijkl"
Vinod Kumar Kachineni
Community Rising Star 2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2019 10:24 AM
Hi there,
You could do something like:
var yourArray = [];
yourArray.push('abcd');
yourArray.push('efgh');
yourArray.push('ijkl');
yourArray.join();
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2019 10:28 AM
Hi there,
If your current output is exactly abcd, efgh, ijkl.
var oldOutput = 'abcd,efgh,ijkl';
splitOutput = oldOutput.split(',');
var yourArray = [];
for(var i = 0; i < splitOutput.length; i++) {
yourArray.push(splitOutput[i]);
}
yourArray.join();
gs.info(yourArray);
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2019 10:29 AM
Hello Irfa,
Check out this:
var userDetails = [];
var grUser = new GlideRecord('sys_user');
grUser.addActiveQuery();
grUser.setLimit(10);
grUser.query();
while(grUser.next()){
userDetails.push(grUser.first_name);
}
gs.print("Array element:"+userDetails.toString());
Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2019 10:37 AM
Hello Irfan,
What mark posted is also correct. But my code will be generic. It will store as many strings as you want.
Thanks!
Abhishek Gardade
Abhishek Gardade