- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 01:23 PM
I have a need to return all the values from a reference column. Here is my code:
var startGR = new GlideRecord('some_table');
startGR.addQuery('some_column', 'some value');
startGR.query();
if (startGR.next()){
var refRecord = startGR.some_ref.getRefRecord();
gs.debug (JSON.stringify(refRecord));
}
When I look at the output I have something like this:
{
"sys_id": {},
"prop1": {},
"prop2": {}
}
It appears as though, I'm only getting the structure. Is there anyway to get something like this:
{
"sys_id": "3f86aedd47517190fwer8f0bd436d4358",
"prop1": "car",
"prop2": {
"sys_id": "5t86aedd475171werwebd436eerd4358",
"name": "green"
}
}
or just this:
{
"sys_id": "3f86aedd47517190fwer8f0bd436d4358",
"prop1": "car",
"prop2": {}
}
Without having to manually add each property.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 05:29 AM - edited 09-20-2023 05:31 AM
Running
var activeFieldNames = global.j2js(GlideTableDescriptor('incident').getActiveFieldNames()),
records = new global.GlideQuery('incident')
.get('01d50b4287e7211007eb63573cbb359a', activeFieldNames);
gs.debug('\n\n' + JSON.stringify(records, null, '\t'));
in Scripts - Background prints
{
"_value": {
"sys_id": "01d50b4287e7211007eb63573cbb359a",
"actions_taken": "",
"active": true,
"activity_due": "",
"additional_assignee_list": null,
"approval": "not requested",
"approval_history": "",
"approval_set": null,
"assigned_to": null,
"assignment_group": "dbe8cbc4878b5d10158298683cbb35aa",
...
"work_end": null,
"work_notes": "",
"work_notes_list": null,
"work_start": null
},
"_lazyValueFetched": false
}
Though GlideTableDescriptor is not accessible from private scopes, so you would need to create a Script Include accessible from all scopes to include the script above - if this is needed in a private scope.
That or create from scratch a Script Include to provide the same functionality: loading active fields for a table.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 01:35 PM
Can you try with below example.
var grIncident = new GlideRecord("incident");
grIncident.query();
grIncident.next();
gs.print(JSON.stringify(new GlideSPScriptable().getFieldsObject(grIncident,"caller_id"))); // add your reference field
Reference:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 01:59 PM
Thanks for help, but I'm running the Toyko version.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 02:13 PM
try to run in background script, it will work on Tokyo as well,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 05:08 AM
Thanks for your help, but it is not working for me. I'm getting java NullPointerExceptions. Also based on the documentation, it looks like it return names and not values.
java.lang.NullPointerException: org.mozilla.javascript.JavaScriptException: java.lang.NullPointerExceptio