- 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 11:13 PM
why don't you do glide record on table to get the field value ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2020 12:21 AM
hi , I had a Problem with the code ,
can you help me with it
I had sysid of the record
and Table name .
ar arr_fields=[];
var fields = new GlideRecord('sys_dictionary');
fields.addQuery('name','x_445906_your_data_demo2'); // 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.info(arr_fields[i]);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2020 12:23 AM
instead of doing glide record on "sys_dictionary" table, kindly try on "x_445906_your_data_demo2" table to get the reference field value details.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2020 12:40 AM
yes ,
Thanks . you have understood .
var 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_label.toString()+"("+fields.element.toString() + ")" );
}
for(var i=0; i<arr_fields.length; i++)
{
gs.info(arr_fields[i]);
}
var 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_label.toString()+"("+fields.element.toString() + ")" );
}
for(var i=0; i<arr_fields.length; i++)
{
gs.info(arr_fields[i]);
}
What is that , I have to change to get REFRENCE fIELD VALUES ??
ThankYou ,

- 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());
}
}
}