- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2024 05:49 PM
Hello all,
I have a reference variable in a catalog item and a list collector variable.
Reference field type variable: (u_field1)
List collector type variable: (u_field2)
Based on reference field selection, its corresponding values has to be populated or shown in list collector for selection.
I have written a script include and Reference qualifier.
But the list e=collector is displaying only one value but not all the related ones.
I have out log messages and observed, "Array is" log is giving two sys_ids, but why the list collector is displaying only one?
My code screenshot:
Script:
var Cat_scripts = Class.create();
Cat_scripts.prototype = {
initialize: function() {},
getActiveContracts: function(cn) {
gs.log("CN is "+cn);
var ar = [];
var gr = new GlideRecord('ast_contract');
gr.addQuery('account', cn);
gr.query();
while (gr.next()) {
ar.push(gr.sys_id);
gs.log("Array is "+ar);
}
return ar;
},
type: 'Cat_scripts'
};
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2024 05:57 PM
By the way, the reason its not pushing multiple values is because your array push is incorrect.
Replace:
ar.push(gr.sys_id);
With:
ar.push(gr.sys_id.toString());

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2024 05:55 PM
Why do you need a reference field to pick values and pass it to a list collector field?
The List Collector also does the job of a reference field.
You can simply remove the reference field in this case.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2024 05:57 PM
By the way, the reason its not pushing multiple values is because your array push is incorrect.
Replace:
ar.push(gr.sys_id);
With:
ar.push(gr.sys_id.toString());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2024 06:05 PM
Hello Anirudh,
It's working.
But why.toString() ?
Regards,
Pallavi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2024 06:10 PM
I'll tell you if you mark my answer correct...😉
ok kidding, not an expert at how javascript works... but it seems push overwrites existing element inside the array when in a while loop unless there is a toString()