- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2024 03:31 AM - edited 03-07-2024 03:33 AM
hello all,
I need to query 2 different tables and return the answers. How to do it from script include?
var loggedIn = gs.getUserID();
var grgetUser = new GlideRecord('u_m2m_sys_user_cmdb_ci');
grgetUser.addQuery('sys_user',loggedIn);
grgetUser.addQuery('sys_user.active','true');
grgetUser.query();
if(grgetUser.next()){
return true;
}
else{
return false;
}
//
var grgetUser1 = new GlideRecord('cmdb_ci_service');
grgetUser1.addQuery('u_psme',loggedIn);
grgetUser1.addQuery('u_psme.active','true');
grgetUser1.query();
if(grgetUser1.next()){
return true;
}
else{
return false;
}
how to combine the results. What this script include was doing with one table is
now I need to have additional query from a completely different table.
basically if the answer is yes on table1 it has to show the menu OR if answer is true from table2 it has to show the menu.
How to achieve the same?
@Dr Atul G- LNG @Mark Manders @James Chun @Ankur Bawiskar @Harish KM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2024 04:45 AM
HI @DB1 ,
May be you can try something like this, store the true false values in a variable and compare those 2 and return true /false based on that,
varloggedIn =gs.getUserID();
vargrgetUser=new GlideRecord('u_m2m_sys_user_cmdb_ci');
grgetUser.addQuery('sys_user',loggedIn);
grgetUser.addQuery('sys_user.active','true');
grgetUser.query();
if(grgetUser.next())
{
var m2mUser = 'true';
}
else
{
var m2mUser = 'false';
}
var grgetUser1=new GlideRecord('cmdb_ci_service');
grgetUser1.addQuery('u_psme',loggedIn);
grgetUser1.addQuery('u_psme.active','true');
grgetUser1.query();
if(grgetUser1.next())
{
var cmdbUser = 'true';
}
else
{
var cmdbUser ='false';
}
if(m2mUser == 'true' || cmdbUser == 'true'){
return true;
}
else {
return false;
}
Let me know if you get any error
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2024 03:45 AM
so now you need to know should it be AND condition or an OR condition?
based on that you can have the logic
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2024 03:54 AM
it has to be OR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2024 04:23 AM
Hi @DB1 ,
Can you try below code to see if the condition works for you :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2024 04:43 AM
I don't think it can be on the else part. Because both conditions are needed from each table it has to be both table1 query = pass as well as table2 query =pass
So it has to be OR