Case insensitive Glide Record query

Katie A
Mega Guru

Is there a way to make a glidequery to be case INSENSITIVE?

In other words, I want to check if a record already exists based on a user input string.

I want to match regardless of case.

For example, if the computer name ac123-123 already exists in the database, I want to match the query regardless of whether the user types in AC123-123 or aC123-123 or Ac123-123.

Here is the Catalog Client Script onSubmit.

This will only match if the case is exact. I want to cover all possible case combinations.

                      var cmp_name = g_form.getValue('u_name');

                      var cmpCI = new GlideRecord('cmdb_ci');

                      cmpCI.addQuery('name',cmp_name);

                      cmpCI.query();

                      if (cmpCI.next()){

                                              g_form.showFieldMsg('u_name','Computer name already exists! Unable to create computer.','error');

                                              return false;

                      }

1 ACCEPTED SOLUTION

Hmm, I just tried a client side GlideRecord in my dev instance. I threw this together and it found three Johns when I queried for lowercase.


function onSubmit() {


        var hi = '';


        var gr = new GlideRecord('sys_user');


        gr.addQuery('first_name', 'john');


        gr.query();


        while(gr.next()){


                  hi += gr.name.toString();


        }


        alert(hi);


}



Result:


find_real_file.png


View solution in original post

5 REPLIES 5

Robert Beeman
Kilo Sage

I didn't realize client side GlideRecord queries were case sensitive. You could (and probably should for performance reasons) do a synchronous GlideAjax call instead and do a server side GlideRecord query in your script include. Server side is case insensitive.


Hmm, I just tried a client side GlideRecord in my dev instance. I threw this together and it found three Johns when I queried for lowercase.


function onSubmit() {


        var hi = '';


        var gr = new GlideRecord('sys_user');


        gr.addQuery('first_name', 'john');


        gr.query();


        while(gr.next()){


                  hi += gr.name.toString();


        }


        alert(hi);


}



Result:


find_real_file.png


Yes you are right it is case insensitive. Thanks for the example. Would you suggest that I also convert my results to a string?



  1. while(gr.next()){  
  2.                   hi += gr.name.toString();  
  3.         }  

Does the "+" in the "+=" set the GlideRecord to case insensitive?