Check case sensitive in addQuery filter condition

sana11
Kilo Guru

Hi All,

I have a reference field in my catalog form, on choosing of values fetching data from another table. Here I have duplicate names for some records but case sensitive is different. So I just want to get result data only to the name which I passed.

For example.

var gr= new GlideRecord('location');

gr.addQuery('country','INdia'); //should return exact results of INdia not india,INDIA and whatever is available in table.

gr.Query();

 

Can anyone suggest some ideas ?

Thanks!

 

 

 

 

14 REPLIES 14

Azim Kazi
Giga Guru

Hi Sana,

addQuery always return Case content so this script will work properly if you still facing issue, kindly share screenshot so that I can assist you better.

 

Hope this will help you 🙂

 

If my response helps you then kindly mark my answer helpful 👍and correct ✔otherwise if any query 🤔 feel free to ask further.

Thanks,

Ajim.

thank you so much for quick reply ..so this script will work properly if you still facing issue.. may i know which script? sorry if i misunderstood anything.

this script means yours, that will work properly

👇

 

var gr= new GlideRecord('location');

gr.addQuery('country','INdia'); 

 

this is correct because of addQuery itself case sensitive 

Hi Sana,

here is an article which might help you:

Many of us use GlideFilter to compare condition fields to a particular record to see if the record matches the condition.

You’ll see an example of this in the Process SLAs business rule where the system runs through all the SLA definitions and checks if the current record matches the conditions on the SLA definition.

I have been using this recently on some custom code and configuration and noticed something that has never cropped up before, namely that the conditions are case sensitive. So what this means the conditions ‘name=ahmed’ is different to ‘name=Ahmed’.

Usually this doesn’t impact me because I don’t use free text fields on conditions, but in this scenario I needed to. What makes this more difficult is that GlideRecord is case insensitive. So if I did a gr.addQuery(‘name’,’ahmed’) it would bring back all records where name was ‘ahmed’ or ‘Ahmed’.

So with a bit (a lot of) digging and searching blogs and community posts, I found a solution to this.

So the original code that’s used is:

var matches = GlideFilter.checkRecord(currentRecord, conditionString);

The new code isn’t quite as concise, but works in the exact same way:

var filter = new GlideFilter(conditionString, “rule”);
filter.setCaseSensitive(false);
matches = filter.match(currentRecord, true);

Using this, you can even create a ‘case sensitive’ field on the configuration table you’re ready from and then set the case sensitive flag accordingly.