Query Optimization Suggestion
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2017 11:26 AM
My requirement is to display the list of macro records which are developed/owned by the logged in users or the logged in user is part of the macro team
now i m writing two Glide record queries, the first one is to get the logged in users team and then using it in my second query
The second query return the list of sysid's
Then i m using it in my URL as
https://xxx.service-now.com/x_opt_macro_govern_macros_list.do?sysparm_query=sys_idINjavascript:new MacroTeam().getMyMacros()
Am i repeating the query condition again and again? And is there a way where we can do this in much efficient method?
getMyMacros: function(){
var arr=[];
var macros=[];
var gr=new GlideRecord('x_opt_macro_govern_macro_team_leaders');
gr.addQuery('team_leader',gs.getUserID());
gr.query();
while(gr.next()){
arr.push(gr.getValue('macro_team'));
}
var myMacro=new GlideRecord('x_opt_macro_govern_macros');
var query1=myMacro.addQuery('development_team_developer',arr.join());
query1.addOrCondition('developer',gs.getUserID());
myMacro.addOrCondition('owner',gs.getUserID());
myMacro.query();
while(myMacro.next()){
macros.push(myMacro.getValue('sys_id'));
}
return macros.join();
}
Also, one more query, its not relevant to my actual post though.. if i use my myMacro.sys_id in the while loop its not giving correct output but when i use myMacro.getValue('sys_id'), it works fine.. are there any differences?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2017 12:04 PM
Hi
Your script looks fine. Even though you may do a lot of loops you actually only do two queries so the load on the server is minimal. Its more important that you ensure that the fields used in the queries are indexed if you have more than 500 records in the tables.
The reason for you second question is the myMacro.sys_id will push a symbolic link to the gliderecord in your array.
And as you are itterating through all the items in the gliderecord you will end up with an array containing symbolic links all pointing to the same sys_id of the last gliderecord. So by using getValue you insert the string value instead

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2017 12:09 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2017 12:21 PM
Thanks davidd.
Actually at the end of the two queries, i m getting all of my SysID.. And again, i m passing the sysid, to the URL query string which is the reason for my concern.. Is it something similar to making another gliderecord query?
I dont have an option to eliminate first two Glide record queries though....
Any suggestions or recommendations?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2017 12:18 PM
Thanks larstange
Actually at the end of the two queries, i m getting all of my SysID.. And again, i m passing the sysid, to the URL query string which is the reason for my concern.. Is it something similar to making another gliderecord query?
I dont have an option to eliminate first two Glide record queries though....
And as far as the second question, you got it exactly right.. the same reason why i asked it.. What does symbolic link means?