I have two table named A and B in both table 6 and 10 records are inserted respectively, in both table one field is common. How can we compare the records f both table using that common field and found that records which are not in the table A.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2017 11:44 AM
I have two table named A and B in both table 6 and 10 records are inserted respectively, in both table one field is common. How can we compare the records of both table using that common field and found that records which are not in the table A.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2017 06:58 PM
Hi Abhiram,
Use a Join query and you only need to create two GlideRecord calls instead of 10 (or however many records are in table2)...
-Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2017 09:28 PM
what i am looking for is-- in table A where 6 records entered, it's 1 record is not available in table B(where 10 records entered), so i want to find out that one record which is in Table A but not in Table B.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2017 07:36 PM
Check if its possible with database view.
http://wiki.servicenow.com/index.php?title=Database_Views#gsc.tab=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2017 09:30 PM
what i am looking for is-- in table A where 6 records entered, it's 1 record is not available in table B(where 10 records entered), so i want to find out that one record which is in Table A but not in Table B.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2017 11:44 PM
Hi Abhi,
For that scenario, and using the script from earlier:
var grMatch = new GlideRecord('A');
grMatch.addJoinQuery('B', 'tableAfield', 'tableBfield');
grMatch.query();
var matchesFound = [];
while(grMatch.next()){
matchesFound.push(grMatch.tableAfield.toString());
}
var grNoMatch = new GlideRecord('A');
grNoMatch.addEncodedQuery('tableAfieldNOT IN' + matchesFound.join());
grNoMatch.query();
while(grNoMatch.next()){
//do something with the records, (e.g.)
gs.print(grNoMatch.getDisplayValue());
}
-Brian