8 Replies · Latest reply on Dec 7, 2017 5:15 PM by Robert Cartwright

    Need to sort choices by Sequence in Catalog Client Script

      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