- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2022 06:32 AM
Guys - I have a requirement to search data in two tables in ServiceNow .
Example - I need to check value of customer_contact field in (sys_user) table if value found that's fine but if not then I need to check another table (customer_account) for field u_contact .
Please help me , how to write two glide records in same function based on condition.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2022 06:41 AM
Hi,
it would look like this; enhance it from your side.
var gr = new GlideRecord("sys_user");
gr.addQuery("customer_contact", "your value");
gr.query();
if (gr.next()) {
// do something
}
else{
var rec = new GlideRecord("customer_account");
rec.addQuery("u_contact", "your value");
rec.query();
if(rec.next()){
// do something
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2022 06:37 AM
Hi Kush,
You can GlideRecord one table and use if else and GlideRecord second table in else statement.
var gr = new GlideRecord('sys_user');
gr.addQuery();
gr.query();
if(gr.next){ //if or while
//do this
}
else{
var gr1 = new GlideRecord('customer_account');
gr1.addQuery('u_contact','yourValue');
//query
//if or while{
}
}
Mark Correct or Helpful if it helps.
***Mark Correct or Helpful if it helps.***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2022 06:41 AM
Hello
you can try this
var gr = new GlideRecord('sys_user');
gr.addQuery('customer_contact','<your_value>');
gr.query();
if(!gr.next())
{
var cus = new GlideRecord('customer_account');
cus.addQuery('u_contact','<your_value>');
cus.query();
if(cus.next())
{
//execute your logic
}
}
else
{
//execute your logiv
}
MARK MY ANSWER CORRECT IF IT HELPS YOU
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2022 06:41 AM
Hi,
it would look like this; enhance it from your side.
var gr = new GlideRecord("sys_user");
gr.addQuery("customer_contact", "your value");
gr.query();
if (gr.next()) {
// do something
}
else{
var rec = new GlideRecord("customer_account");
rec.addQuery("u_contact", "your value");
rec.query();
if(rec.next()){
// do something
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader