Is addQuery case sensitive?

mitzaka
Mega Guru

Hi, I want to know is addQuery case sensitive? My case is that I have a business rule, which calls a script include in which I am using the addQuery option. The script include aims to check for duplicate records in a table. However, what I want is for this to be case sensitive as right now if I have a record Test and then try to enter another record TEST I am unable to do so.

My code for the script include is:

var CIMatcher = Class.create();

CIMatcher.prototype = {

  initialize: function(current) {

  this.record = current;

  },

  getCIIdentifier:function (){

  var gr = new GlideRecord('u_ci_class_lookup');

  gr.addQuery('u_ci_class',this.record.sys_class_name);

  gr.query();

  if(gr.next()){

  var i = 0;

  var ciclass = ''+ gr.u_ci_class;

  //split all our field names into something we can query

  var fields = gr.u_fields.split(',');

  var ci = new GlideRecord(ciclass);

  ci.addQuery('sys_id','!=',this.record.sys_id.toString());

  //loop through all fields in lookup table with values from 'current'

  while(i < fields.length){

  var field_value = eval("this.record." + fields[i].toString());

  if(JSUtil.nil(field_value.trim())){

  return false;

  }

  ci.addQuery(fields[i].toString(),field_value);

  i++;

  }

  ci.query();

  if(ci.next()){

  new CIException().add(this.record,'Duplicate');

  return false; //abort insert log exeception

  }

  return true;//nothing found proceed as normal

  }

  //no class identifier for this table

  return true;

  },

  type: 'Matcher'

};

9 REPLIES 9

Chuck Tomasi
Tera Patron

Yes, addQuery's parameters are case sensitive. The field name must appear as it does in the dictionary (e.g. u_number, not u_Number) and the value must match the value as well. ("normal" is different than "Normal").


Alright, for the sake of clarity here is what I received from ServiceNow support after I had submitted my question there as well. ctomasi - I got an answer oposite to the one you suggested here, so I asked what to take for source of truth. Here is what I got back:



Me:


Which should I take for true - your answer or the answer from the community by one of the ServiceNow architects?



Support Person:



Me. You may Customer Support to have the right answer. Anyone can write anything on the forum. Column/Field names are clearly case sensitive, as they are everywhere in the platform, including client side forms and every API. I assumed you already knew that and this was not your question. I think Chuck is mistaken on the second half of his answer. The important bit is the 'value', the second parameter (or 3rd is using an operator), which is case in-sensitive. e.g. rename 3 computer CIs as "IBM", "Ibm" and "ibm". Run this: var daveGr = new GlideRecord('cmdb_ci_computer'); daveGr.addQuery('name','ibM'); daveGr.query(); gs.print(daveGr.getRowCount()); This will find all 3 every time, regardless of the combination of upper or lower case letters in the value parameter, and always has done. This has been the case at least back to the Aspen release.



So I think this is a clear explanation which I am happy with. Thought it's useful to share it.


Dimitar


Thanks for sharing Dimtar!



I'm afraid I don't see the contradiction/confusion (which means it's probably on my end of the keyboard.) We're still both saying the same thing. The field names and values are case sensitive in a query.


Maybe I got confused as well. Anyway, thank you for the replies , they are helpful!