1 Select Box choice to be display at the bottom

narayansaha
Tera Contributor

Hello All,

Good day! I would like to get some help on 1 stuff, where a select box choices should be displayed in alphabetical order.
However, there are some cases, where choices like "Any other"/ "Other" should be displayed at the bottom.

The select box and the choices are specific to the Application Name selected. And we have configured a catalog client script, script include and custom table, from where we are populating the choice list for specific Application Name.

I want to know, how we can put the choices like "Any other", "Other" at the bottom, while the remaining choice lists to be in alphabetical order.

Dropdown.jpg

Catalog Client Script: OnChange of "Application Name" variable

function onChange(control, oldValue, newValue, isLoading) {

  if(newValue == oldValue){

  return;

  }

  if(!isLoading && newValue!=''){

  var appName=g_form.getReference('<Application Name variable>').name;

  g_form.getControl('App_Issue_Type').options.length = 1;

  var ajax=new GlideAjax('XL_SCAT_ChoiceList1_SoftwareIssues');

  ajax.addParam('sysparm_name','choiceLis1Values');

  ajax.addParam('sysparm_choice',appName); //Pass userID as parameter

  ajax.getXMLWait();

  var ans = ajax.getAnswer();

  var list1=ans.split('^');

  for(var i=1;i<list1.length;i++){

  g_form.addOption('<Type of Issue>', list1[i],list1[i]);

  }

  }

}

Script Include: Client Callable checked

var XL_SCAT_ChoiceList1_SoftwareIssues = Class.create();

XL_SCAT_ChoiceList1_SoftwareIssues.prototype = Object.extendsObject(AbstractAjaxProcessor, {

  choiceLis1Values: function() {

  var answer='';

  var choice=this.getParameter('sysparm_choice');

  //var element=this.getParameter('sysparm_element');

  var gp = new GlideRecord('u_xl_scat_choice_list_table');

  gp.addQuery('u_reference_field', choice);

  gp.orderBy("u_field_1");

  gp.query();

  while(gp.next()){

  if(answer.lenght==0){

  answer=gp.u_field_1;

  }else{

  answer=answer+"^"+gp.u_field_1;

  }

  }

  return answer;

  }

});

Custom Table: XL SCAT Choice List Tables

XL SCAT Choice List Tables.jpg

Any urgent help should be highly appreciated.

Regards,

Narayan Saha

7 REPLIES 7

amaradiswamy
Kilo Sage

Hi Narayan,



You can use the index to control at what position a choice should be shown in drop-down.



addOption('field','value','label','index');


g_form.addOption('priority', '2.5', '2.5 - Moderately High', 3); //2.5 choice will be third choice in drop-down list



You can check the label of choice before adding choice like


  for(var i=1;i<list1.length;i++){


if(list1[i] == 'Other')


{


  g_form.addOption('<Type of Issue>', list1[i],list1[i],list1.length-1);


}


else


{


g_form.addOption('<Type of Issue>', list1[i],list1[i],i);


}


  }



http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#addOption



Regards


Swamy


Hello Amaradi,



Thanks much for your feedback. But unfortunately, it has no change on anything.
The choice lists are still showing in alphabetical order with "Any other issue" option in top, even I have modified the script accordingly.



Clien Script.jpg




Regards,


Narayan Saha


What is the choice value of 'Any Other' choice not the label?


Hello Amaradi,



The label and value are same.



Orderwise.bmp





Regards,


Narayan Saha