
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2016 02:47 PM
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;
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2016 03:32 PM
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2016 03:14 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2016 03:32 PM
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:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2016 04:39 PM
Yes you are right it is case insensitive. Thanks for the example. Would you suggest that I also convert my results to a string?
- while(gr.next()){
- hi += gr.name.toString();
- }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2019 10:38 AM
Does the "+" in the "+=" set the GlideRecord to case insensitive?