The CreatorCon Call for Content is officially open! Get started here.

How to Get Related Child Records of a Record ??

Tarun2
Tera Contributor

Hi , 

I  Want to get Related  Child Records of a Record .

Explanation :

I have a Record , which is Parent to Multiple Records of Another Table .

Two Tables  " Table "  and " Column"

  " Table " has 1 Record . 

  " Column "  has 5 Records .( These 5 Records are Child of " Table "   Record 1  via Reference Field . 

 

shown Below :  Column Record named "ACTIVE " Is child of "Table " Record  Customer ,

find_real_file.png

      Now , 

I want to get all the Child Records By Giving " TABLE "  Record  "sysId"

Here i dont have Child Table Name . 

I have Parent Table name , Parent Record sysid  

i need Parent Record's Child Records 

 

 

Kindly help me with the code ,

Thankyou ,

 

   

 

1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron
Try now
 
 
var child = new GlideRecord('Table name');

child.addQuery('sys_id', 'sys_id of parent record ');

child.query();

if(child.next())

{
var child1 = new GlideRecord('<related list table name>');

child1.addQuery('<Column which make the relation >',child.sys_id);
child1.query();
while(child1.next())
{
gs.info(child1.name);
}

}

View solution in original post

3 REPLIES 3

Mohit Kaushik
Mega Sage
Mega Sage

Hi there,

you can get it easily

var child = new GlideRecord('<'name of column table'>');

child.addQuery(<back end value of table field>,'sys id you have');

child.query();

while(child.next())

{

gs.print(child.name);

}

 

Thanks,

Mohit Kaushik

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

Hi  Thanks , 

Here i dont have Child Table Name . 

I have Parent Table name , Parent Record sysid  

i need Parent Record's Child Records 

can you help me with this .

Thanks ,

 

Harsh Vardhan
Giga Patron
Try now
 
 
var child = new GlideRecord('Table name');

child.addQuery('sys_id', 'sys_id of parent record ');

child.query();

if(child.next())

{
var child1 = new GlideRecord('<related list table name>');

child1.addQuery('<Column which make the relation >',child.sys_id);
child1.query();
while(child1.next())
{
gs.info(child1.name);
}

}