
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2018 12:02 PM
I am having a problem with the values of a List field and getting them into an array.
The List field itself on my form takes on multiple selection options for different Reference items but when I print the value in a background script, it is all print as a string, one value, instead of an array that I can use to do something with EACH of the sys_ids in the List field. Here is an example of what I am running into:
- List Field contains 2 reference records, COMMITTEE ONE, COMMITTEE TWO
- Print/Alert the List Field Value: 7b401a7b4fc2fe00475a4b8e0210c721,dce9eeaf4f38038036cf76601310c795
I have tried the following and it still isn't working.
var queryString = '0623cec74f8c5f005fed650f0310c7ab';
var ar = [];
var gr = new GlideRecord('task');
gr.addQuery('sys_id', queryString);
gr.query();
if (gr.next()) {
var str = gr.list_field.toString();
var splt = str.split(',');
ar.push(splt);
gs.print("Array Value: " + ar); // Output is 7b401a7b4fc2fe00475a4b8e0210c721,dce9eeaf4f38038036cf76601310c795
gs.print("Array Length: " + ar.length); // Output is 1
I also tried:
var str = gr.list_field;
var splt = str.split(',');
That didn't work either, it still prints as one string.
I cannot get the string value of the List field to separate at the comma so that I can use each individual sys_id to dome something else.
Any ideas?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2018 12:07 PM
Hi Kyle,
Ideally var splt on line 9 is an array, dont push it anywhere.
When you are pushing it in ar you are creating an array of array
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2018 12:07 PM
Hi Kyle,
Ideally var splt on line 9 is an array, dont push it anywhere.
When you are pushing it in ar you are creating an array of array

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2018 12:10 PM
That was it! Thanks! I figured it was something to do with my coding... I appreciate it!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2018 12:11 PM
Cheers Mate!!