join() and get.Value instead of push and toString()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2018 06:03 AM
Hello all,
in the following script:
function testing {
var sysIDkey = [];
var GRfilter = new GlideRecord('incident');
GRfilter.addEncodedQuery('category='hardware');
GRfilter.query();
while (GRfilter.next()) {
sysIDkey.push(GRfilter.sys_id.toString());
}
return sysIDkey;
}
I would need to use join() instead of push and getValue instead of toString().
GRfilter.getValue('sys_'id) works fine, but I'm not able to replace push with join() in any modification - result is always javascript:testing() //being used as scripted filter.
Any ideas are most welcomed.
Thanks,
VS

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2018 06:08 AM
I think after pushing only we can use join. Without the array with elements how can we join them. First we need a array with data then we can join it right.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2018 06:09 AM
I think you're getting your array methods mixed up.
push is used to add elements to an array. join is used to get each element and make a string out of it. That return line is where you would use a join if you want to return a string instead of an array. Example: (note the change of toString() to getValue() - better, also fixed the quote problem you have in the addEncodedQuery()
unction testing {
var sysIDkey = [];
var GRfilter = new GlideRecord('incident');
GRfilter.addEncodedQuery('category="hardware"');
GRfilter.query();
while (GRfilter.next()) {
sysIDkey.push(GRfilter.getValue('sys_id'));
}
return sysIDkey.join(','); // return comma separated string of sys_ids
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2018 06:10 AM
It would also help to understand what you are trying to do? Where is this bit of script being used (or called from)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2018 08:51 AM
Hello Chuck,
Thanks very much for the reply. I'm using this as a Script Include to set up a Scripted Filter.
If I now understand the usage and placement of join() correctly, when implemented, the results are wrong because it treats the array fields as one string. when return is kept as it was, the values are sent separately as they should.
join() is therefore not of use in this scenario...if I'm not wrong of course.
Thanks!