How to restrict number of records on Glide List(list collector) of service catalog.

Sharique Azim
Mega Sage

Hi All,

I am trying to restrict the number of records which can be selected in a glide list to be 5.

I can best figure out that   if i can operate something similar to an array concept i can restrict the   selection and alert.

My interest is particularly in glide list, as I dont want to show all the user's name at start.

Piece of my code is

var maxOptions = 5;

  var selectedIDs = [];

  var str= selectedIDs.push(g_form.getValue('users'));

  alert(str);

  alert(str.length); //i know it would store a single string with multiple commas using this code

              var index = 0;

              for(var i = maxOptions; i < str.length; i++){

                      selectedIDs[index] = i;

                      index++;

            }

Kindly advice me on my code or any better approach..

1 ACCEPTED SOLUTION

This may work better as an onSubmit rather than an onChange. That way users can remove those list choices they deem unnecessary rather than relying upon the script to remove all but the first 5 entries. I am using list_variable as the variable name in my example:



function onSubmit() {


      g_form.hideFieldMsg('list_variable', true);


      var chkString = g_form.getValue('list_variable');


      var chkArray = chkString.split(',');


      if (chkArray.length > 5) {


              var eMessage = 'You cannot select more than 5 entries at a time';


              g_form.showFieldMsg('list_variable', eMessage, 'error');


              return false;


      }


}



Let me know if this is more successful since I have not tested it.


View solution in original post

9 REPLIES 9

ccajohnson
Kilo Sage

There are several built in functions that let you configure your GlideList. Take a look at the setRowsPerPage() function:


http://wiki.servicenow.com/index.php?title=GlideList2_(g_list)#setRowsPerPage


Hi Christopher,




I am building a onChange script to perform the job as this is a catalog item..


Can the solution provided by you   work in client side?


I have used g_list as a way of setting a filter on the list in the portal using a client script. Was thinking that the information contained would be helpful. Here is an example I found for catalog:


Client script usage examples


Thanks..I am not setting the filter but restricting the number of selections