glide query size of a string

brumiou
Mega Guru

Hi,

in a business rule, I have to query a table to return all the records with a name with a size of 4 characters.

Is there a way to do that in a glide query?

something like that :

var dep = new GlideRecord("cmn_department");
dep.addQuery("nameLIKE"+current.u_dep_temp);
dep.addQuery("name.length==4");
dep.query();
if(dep.getRowCount() == 1)
....


Thank you so much!

Regards

Xavier

2 REPLIES 2

benn23
ServiceNow Employee
ServiceNow Employee

var arr = [];
var ci = new GlideRecord('cmdb_ci');
ci.query();
while(ci.next()){
if(ci.name.toString().length == 4){
arr.push(ci.name.toString());
}
}
//do something with your array
gs.log(arr.toString());


brumiou
Mega Guru

but I have to query all the table for that, what I'm looking for is a way to query on that size.

but thanks anyway!

The temporary solution I've found is to create a field u_name_size on the table cmn_department. I've a Br before insert or update that update that field.