addQuery for reference field

chidanandadhath
Kilo Guru

The highlighted one is a reference field , how to compare and filter that?

var module=new GlideRecord('sys_app_module');
module.addQuery('active',true);
module.addQuery('application','Configuration');
module.addQuery('link_type','LIST');
module.query();
while(module.next())
{
var menuName=module.title;
var tables=module.name;
gs.print(menuName +"-" +tables);
}

1 ACCEPTED SOLUTION

SanjivMeher
Kilo Patron
Kilo Patron

Try

 

var module=new GlideRecord('sys_app_module');
module.addQuery('active',true);
module.addQuery('application.title','Configuration');
module.addQuery('link_type','LIST');
module.query();
while(module.next())
{
var menuName=module.title;
var tables=module.name;
gs.print(menuName +"-" +tables);
}


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

3 REPLIES 3

SanjivMeher
Kilo Patron
Kilo Patron

Try

 

var module=new GlideRecord('sys_app_module');
module.addQuery('active',true);
module.addQuery('application.title','Configuration');
module.addQuery('link_type','LIST');
module.query();
while(module.next())
{
var menuName=module.title;
var tables=module.name;
gs.print(menuName +"-" +tables);
}


Please mark this response as correct or helpful if it assisted you with your question.

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

Anytime you have a reference field, the SysID is stored as the value of that field.  So in the sys_app_module table, application is a reference to the Application Menu (sys_app_application) table and the value in that field is the SysID of the Application menu record.  So in order to query via GlideRecord, you need the SysID of "Configuration" in your case.  You can "dot-walk" in queries but it is not recommended as it causes table scans.  I don't know enough about what you are trying to achieve to recommend one way or another.

BRUNO BANDEIRA
Tera Guru

I have a question guys! 

 

I'm playing with ServiceNow scripting these days and I got this scenario in a script:

 

/***

gr.addQuery('group.sys_id', '<ANOTHER SYS_ID>'); // Return sys_id from group field

***/

 

Considering that 'group' is a REFERENCE field, when I ask for the field WITHOUT the dot notation, like:

 

/***

gr.addQuery('group', '<ANOTHER SYS_ID>') // ALSO return sys_id from group field

***/

 

The value returned is ALSO a sys_id, right?

 

This dot notation group.sys_id  is just to make a EXPLICIT statement that I want the sys_id or is a OBLIGATORY one?

 

Thanks in advance!