Sorting add options not working

sigmachiuta
Kilo Guru

I am trying to sort my addOptions but i dont have success doing this what i have is a a glide ajax call here is my script include sort is an integer.   This should be passing the sort as the last parameter

      while(gr.next()){

          var a = gr.u_operatingsystem.split(',');

          var result =   this.newItem('os1');

          for(var i = 0 ; i < a.length; i++){

              var na = new GlideRecord('u_operatingsystems');

              na.addQuery('sys_id',a[i]);

              na.addQuery('u_active', 'true');

              na.query();

              while(na.next()){

             

          var b = this.newItem("os");

          b.setAttribute("os", na.u_osdisplayname);

    var c = this.newItem("sort");

    c.setAttribute("sort", na.u_sort);

                 

              }

and here is a snip from my client script the options are showing correct the sort order is just not correct.

  function OsProcessor(response) {

      var sec = response.responseXML.getElementsByTagName("os");

  var srt = response.responseXML.getElementsByTagName("sort");

      for ( var i = 0 ; i < sec.length; i++){

          var n1 = sec[i].getAttribute("os");

          var sort= sec[i].getAttribute("sort");

          g_form.addOption('os', n1, n1, sort);

         

      }

5 REPLIES 5

Sorting my query didnt work.   Thats probably bc i am passing the sys id in from another query that does not have a sort (notice the split on line 2).   Before my for loop in my response i gathered all my values in an array and then sorted them.   After the sort i passed the values into the addOption


Community Code Snippets - Three Methods to Sort an Object Array