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

Hi Shiri,

 

You can add it in anywhere between the GlideRecord and the Query. 

 

Regards,

Robert