Compare 2 values and check even if it's case sensitive
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2022 06:03 AM
Hi,
I am using a client callable script include to compare a value from 'Server' to the one entered in a 'Variable' and if it matches I want to restrict it and clear the variable field, which is working fine.
For eg: If the value on Server is ABC and I enter ABC in the Variable it will clear the variable, but if the value on Server is ABC and I enter abc or Abc in the Variable it will accept it. How do I make this check and make it work even if the values entered are case sensitive?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2022 06:13 AM
Try with i modifier in regex. See the below script for reference.
var str = "ABC";
var regex = /aBc/i;
var result = str.match(regex);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2022 07:43 PM
Hi,
Below is the SI and CS
var AppName = Class.create();
AppName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getAppDetails: function(app) {
var que = this.getParameter('sysparm_app_name');
var gr = new GlideRecord('question_choice');
gr.addEncodedQuery('question=103d1e4bdb3d9810c69960d444961966');
gr.get(que);
var val = gr.getValue('value');
var response = {};
response.value = val;
return JSON.stringify(response);
},
type: 'AppName'
});
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('AppName');
ga.addParam('sysparm_name', 'getAppDetails');
ga.addParam('sysparm_app_name', newValue);
ga.getXMLAnswer(function(answer) {
var response = JSON.parse(answer);
if (newValue == response.value) {
g_form.clearValue('app_name');
}
});
}
How do I make the check here even if the value entered in the variable is upper case or lower case and it matches with the value in question_choice it must clear the variable? I have tried to use the toLowerCase() but it didn't work for me.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2022 08:12 PM
In the client script can you try tis
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var newValueSmall = newValue.toLowerCase();
var ga = new GlideAjax('AppName');
ga.addParam('sysparm_name', 'getAppDetails');
ga.addParam('sysparm_app_name', newValue);
ga.getXMLAnswer(function(answer) {
var response = JSON.parse(answer);
if (newValueSmall == response.value.toLowerCase()) {
g_form.clearValue('app_name');
}
});
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2022 09:01 PM
Hi,
That is working, but it's also clearing when I enter some others values that are not matching. Some times it accepts non matching values but is says ' There is a JavaScript error in your browser console'