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

Himanshu Dubey
Giga Guru

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

hi @Himanshu Dubey 

Thanks.Its working i got Reference Field Names , 

How to get Reference Field Values ?? (using Record Sys_Id)

Thanks ,

 

Do you want all the reference fields values?

Hi , 

Yes , I have sysId of a Record and Table Name

i want Reference Field Values using sysId .

ThankYou ,