How to Get Reference field values of a Record with Record SysId ??

Tarun2
Tera Contributor

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 ,

 

1 ACCEPTED SOLUTION

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



}


}

View solution in original post

13 REPLIES 13

You can directly gilde particular table and pass the sys_id of the record

 

 

var gr = new GlideRecord('incident');  // table name
gr.get('7f71107c1bb60010445ffcc8cc4bcb3f'); //sys_id of record
gr.query();
if(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());
}
}
}
}

Hi, 

No errors BUT 

Results are bot displaying .

test136
Tera Contributor

Its working for me please check your record id is correct or not

It's working for me please check your record id whether it is correct or not