- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2017 02:54 PM
Hi All,
I'm having an issue with a Catalog Client Script. I'm using a template provided by another user in this forum (Pradeep Sharma) which does exactly what I want except it does not order by sequence. I can't seem to get "sort" to work so I am looking for suggestions.
Here is the basic script I am using:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//remove all items from appropriate Access Level drop down to start
g_form.clearOptions('u_access_level_1');
var app = g_form.getReference('u_application');
//build a new list of dependent options
var gpSub = new GlideRecord('sys_choice');
gpSub.addQuery('table','sc_request');
gpSub.addQuery('dependent_value', app.name);
gpSub.addQuery('element', 'u_access_level_1');
gpSub.query(function(gpSub){
while(gpSub.next()){
g_form.addOption('u_access_level_1', gpSub.value, gpSub.label, gpSub.sequence);
}
});
}
What am I doing wrong? What would I need to do to correct it? Bonus points if it can be corrected without using an array (trying to stick with an SOP here).
Thanks in advance! Happy to grant Likes and Correct Answer designations.
Regards,
Robert
Solved! Go to Solution.
- Labels:
-
Incident Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2017 03:21 PM
hi Robert,
try add following between line 14 and 15.
gpSub.orderBy('sequence');
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2017 04:59 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2017 05:02 PM
Yeah...I read that one (which is where I found the "orderByDesc"), but it basically came down to "I think the problem is somewhere else in your script." No help. 😞
Thanks anyhow...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2017 05:10 PM
Though a link in there has good info: https://www.servicenowguru.com/scripting/gliderecord-query-cheat-sheet/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2017 05:15 PM
I stand corrected. Your first suggestion did work (gpSub.orderBy('sequence');). I was just using different test data between instances.
Marking your answer as Correct!
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2020 11:01 AM
Hi
I don't see the numbers in the lines. Can you please indicate which ones are lines 14 & 15?
Where did you enter the sort?