- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2020 11:21 PM
Hi ,
How to know the value of Reference Field values in a Record ? (Value)
var arr_fields=[];
var fields = new GlideRecord('sys_dictionary');
fields.addQuery('name','incident'); // table name
fields.addEncodedQuery('internal_type=reference');//getting reference type fields
fields.query();
while(fields.next())
{
arr_fields.push(fields.column_label.toString()+"("+fields.element.toString() + ")" );
}
for(var i=0; i<arr_fields.length; i++)
{
gs.print(arr_fields[i]);
}
I have multiple reference Fields in Record .
I am getting Reference Field Names (One By One )
But I want Reference Field Values .
Any Suggestion is Appreciated .
Thankyou ,
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2020 12:44 AM
working script:
here i tested the script, for my incident table, same way you can do it for your table.
var gr = new GlideRecord('incident'); // change the table name
gr.addQuery('sys_id','98e902e02f6b4c10f68d5ff62799b609'); // add record id
gr.query();
gr.next();
var fields = gr.getFields();
for(var i = 0;i<fields.size();i++){
var glideElement = fields.get(i);
if (glideElement.hasValue()) {
if(glideElement.getED().getInternalType() == 'reference'){
gs.print(glideElement.getDisplayValue());
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2020 11:26 PM
Hi there,
Could you explain what you are functionally after? Is this your own script or copied from somewhere? Feels like this could be done a lot different/easier.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2020 12:25 AM
Hi ,
can you help me with the easy approach you are Talking about .
i have sysid of record .
ar arr_fields=[];
var fields = new GlideRecord('x_445906_your_data_demo2');
fields.addQuery('sysid','3D1c4aa3702feb48108490dcb6f699b621'); // table name
fields.addEncodedQuery('internal_type=reference');//getting reference type fields
fields.query();
while(fields.next())
{
arr_fields.push(fields.column_name.toString()+"("+fields.element.toString() + ")" ); //instead of label change it to name
}
for(var i=0; i<arr_fields.length; i++)
{
gs.print(arr_fields[i]);
// suppose you are on the same record for which you need the value of reference fields
gs.print(current.arr_fields[i]); //this line will print the value of fields
}
Thankyou

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2020 12:38 AM
Like I mentioned: what is functionally what you are trying to achieve?
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2020 11:37 PM
i think you have already opened a thread for same question. please don't open duplicate thread , reply at one place so it will be easy for us to help you.