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

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...


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!


Shiri
Kilo Contributor

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?