- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2020 03:32 AM
Hi ,
I have few doubts with Scripting
1.How to know How many Reference Fields are present in a Record ?? i have Record sysd_id
and
2.How to know the value of Reference Field in a Record ? Value not , sys_id of field .
My Requirement :
I have a Table:
Schema Table has Refereence Field linked to DataBase Table .
Schema table Record_1 is Linked to Database Table Record_
With Sys_Id of Schema Table Record i want to fetch the Related Record (i.e Database Table Record_1 name )
Thankyou ,
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2020 12:43 AM
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 03:52 AM
Hi Tarun,
Below is the script to get all the reference fields of any table
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]);
}
Please mark correct and Helpful if it helps
Thanks and Regards
Himanshu Dubey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2020 04:53 AM
hi
Thanks.Its working i got Reference Field Names ,
How to get Reference Field Values ?? (using Record Sys_Id)
Thanks ,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2020 09:53 PM
Do you want all the reference fields values?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2020 10:10 PM
Hi ,
Yes , I have sysId of a Record and Table Name
i want Reference Field Values using sysId .
ThankYou ,