- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2015 02:48 PM
I am zero clue what I am doing. Someone help me out here!!
I am trying to filter a related list so it only shows projects with certain 'states'. (On Hold, Requested, Pending)
This is what I have that just has one state and it works great.
var gr = new GlideRecord("pm_m2m_portfolio_project");
gr.addQuery("portfolio", parent.sys_id);
gr.query();
var ids = [];
while (gr.next()) {
if (!gr.project.pm_project.nil()) {
ids.push(gr.project.pm_project.toString());
}
}
current.addQuery("sys_id", ids);
current.addQuery('state', 11);
But I am not sure how to do an OR statement on here. Is is something like ('state', 11 || 12 || 8)?
Or I tried this but it just pulled all the projects and not just those 3 states.
var gr = new GlideRecord("pm_m2m_portfolio_project");
gr.addQuery("portfolio", parent.sys_id);
gr.query();
var ids = [];
while (gr.next()) {
if (!gr.project.pm_project.nil()) {
ids.push(gr.project.pm_project.toString());
}
}
var myObj = new GlideRecord('pm_project');
current.addQuery("sys_id", ids);
var q1= myObj.addQuery('state', 11);
q1.addOrCondition('state',12);
q1.addOrCondition('state', 8);
Thanks for helping me learn how to script! I appreciate it!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2015 04:37 PM
I think the 'IN' operator would be helpful here.
current.addQuery('state', 'IN', 11,12,8);
You may have to put 11,12,8 in quotes. I'm not sure if SN handles the integer/string conversion there. If that doesn't work, you could always use an encoded query string as a shortcut.
current.addEncodedQuery('stateIN11,12,8');
Check out this link for more details...
http://www.servicenowguru.com/scripting/gliderecord-query-cheat-sheet/

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2015 04:37 PM
I think the 'IN' operator would be helpful here.
current.addQuery('state', 'IN', 11,12,8);
You may have to put 11,12,8 in quotes. I'm not sure if SN handles the integer/string conversion there. If that doesn't work, you could always use an encoded query string as a shortcut.
current.addEncodedQuery('stateIN11,12,8');
Check out this link for more details...
http://www.servicenowguru.com/scripting/gliderecord-query-cheat-sheet/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2015 10:48 PM
According to your script , it should be done in this way
var gr = new GlideRecord("pm_m2m_portfolio_project");
gr.addQuery("portfolio", parent.sys_id);
gr.addNotNullQuery('project.pm_project');
gr.addQuery('project.pm_project.state','IN','11,12,8');
gr.query();
gs.log('Total Projects : '+gr.getRowCount());
while (gr.next()) {
gs.log('Project sys_id : '+gr.project.pm_project.sys_id);
gs.log('Project Name : '+gr.project.pm_project.name); // if 'name' is the back end name of column in pm_project tabel.
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2015 01:22 PM
Thanks Mark! CrozzFuse is the best!
current.addQuery('state','IN', '11,12,8'); - quotes were like this for it to work!