Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Relationship among Tables

Madhan007
Tera Contributor

Hi Everyone,

I have Three Tables A,B and C. Table B has a field referring to Table A , and Table C has a field referring to Table B. Now I want the list of Matching Records from Table C as a Related List in Table A. I have created a Relationship Record bw Table A and Table C,but I am having a hard time querying the Matching records in Table C. 

How can I do it ?

Please pour Your Thoughts.Thanks in Advance.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Madhan007 

something like this

Applies to Table - Table A

Queries from Table - Table C

Script:

var tableBArr = [];
var gr = new GlideRecord("table B");
gr.addQuery("fieldReferringToTableA", parent.sys_id);
gr.query();
while (gr.next()) {
    tableBArr.push(gr.getUniqueValue());
}

current.addQuery('fieldReferringToTableB.sys_id', 'IN', tableBArr.toString());

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@Madhan007 

something like this

Applies to Table - Table A

Queries from Table - Table C

Script:

var tableBArr = [];
var gr = new GlideRecord("table B");
gr.addQuery("fieldReferringToTableA", parent.sys_id);
gr.query();
while (gr.next()) {
    tableBArr.push(gr.getUniqueValue());
}

current.addQuery('fieldReferringToTableB.sys_id', 'IN', tableBArr.toString());

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader