Need to sort choices by Sequence in Catalog Client Script

Robert_Cartwrig
Tera Expert

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

1 ACCEPTED SOLUTION

Bryan Tay3
Mega Guru

hi Robert,



try add following between line 14 and 15.


gpSub.orderBy('sequence');  



Hope this helps.


View solution in original post

10 REPLIES 10

Bryan Tay3
Mega Guru

hi Robert,



try add following between line 14 and 15.


gpSub.orderBy('sequence');  



Hope this helps.


I had wanted to try orderBy as I know it from SQL, but never did.   Was using javascript "sort" (ineffectively).



I tried "gpSub.orderBy('sequence');"   (and a couple of variations), but no-go. It still sorts by sys_created_on.



Any other ideas?



Thanks,


Robert


I just tried it with "gpSub.orderByDesc('sequence');"   That works!



Wouldn't have found it without your help, so I'm giving you a Like and a Helpful.   Don't want to mark it as Correct and mislead folks...



Cheers!


Robert


I stand corrected...after more extensive testing, "gpSub.orderByDesc('sequence');" doesn't work either. 😞



Any other bright ideas?



Thanks,


Robert