- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 03:48 AM
Hi,
I need to push multiple values into a glide list field from records retrieved from gliderecord. Currently it's only pushing one value. Is there something simple I'm missing? I've logged it and the glide record is returning 5 records.
(function executeRule(current, previous /*null when async*/) {
var m2moim = new GlideRecord('x_lbg_insider_risk_m2m_catalog_acce_ir_access_ca');
m2moim.addQuery('ir_access_categorisation', current.sys_id);
m2moim.query();
while (m2moim.next()) {
//gs.info("AB 28_07 " + m2moim.sys_id);
var entList = [];
entList.push(m2moim.catalog_access);
current.u_oim_entitlements = entList.toString();
}
})(current, previous);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 05:44 AM
Hello Brack,
Below please find the updated working code.
(function executeRule(current, previous /*null when async*/) {
var entList = [];
var m2Gr = new GlideRecord('x_lbg_insider_risk_m2m_catalog_acce_ir_access_ca');
m2Gr.addQuery('ir_access_categorisation', current.sys_id);
m2Gr.query();
while (m2Gr.next()) {
entList.push(m2Gr.catalog_access.toString());
}
current.u_oim_entitlements = entList.join();
})(current, previous);
- Pradeep Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 04:01 AM
you have to use the following:
entList.push(m2moim.getValue('catalog_access'));
m2moim.catalog_access is a GlideElement (complex object) and is stored by reference (it´s like storing the same object in every loop).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 04:33 AM
Thanks Sebastian. This still only pushes one sys_id into the list rather than multiple.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 04:06 AM
Few things You need to do this;
1) use toString() while pushing the value into the array
2) Also you should set the value once your while loop ends
(function executeRule(current, previous /*null when async*/) {
var m2moim = new GlideRecord('x_lbg_insider_risk_m2m_catalog_acce_ir_access_ca');
m2moim.addQuery('ir_access_categorisation', current.sys_id);
m2moim.query();
while (m2moim.next()) {
//gs.info("AB 28_07 " + m2moim.sys_id);
var entList = [];
entList.push(m2moim.catalog_access.toString());
}
current.u_oim_entitlements = entList.toString(); // this line outside the while loop
})(current, previous);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 04:33 AM
Thanks Ankur. Unfortunately, still only getting one value in the list