script to return all reference of reference list field
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2024 06:27 PM
Hi
I have a field of type reference list
I am trying to write a script that returns me all the SYS ID
For example -
In the groups table I have a record named X and Y and Z are registered
And record Y has a record U and Q
Finally I want to output an array of X,Y,Z,Q,U
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2024 03:10 AM
This should get you started - assuming Secondary Group is a list field referencing the groups table:
var grpArr = [];
var grpGr = new GlideRecord('sys_user_group');
//addQuery criteria?
grpGr.query();
while (grpGr.next()) {
grpArr.push(grpGr.sys_id.toString());
if (grpGr.u_secondary_group) { //custom list field name
grpArr.push(grpGr.u_secondary_group.toString().split(','));
}
}
var arrayUtil = new ArrayUtil();
var uniqueArray = arrayUtil.unique(grpArr);