Querying on length of data

johnsgp
Mega Expert

I would like a query to find those rows in a database table where the length of the data in the field meets a certain condition.   For example, I want all users where the length of the phone number is greater than 15 - this could indicate a data entry problem, for example.

How can this be done using a GlideRecord?

(I have a similar question regarding doing such queries on a List view in the UI.)

11 REPLIES 11

That's the way! thanks! btw how did you find that?

Palash Sarkar1
Giga Expert

There was a requirement that the Short Description field be shortened from 255 character length. Field cannot be changed in the table, because the data already contains long characters.

I create in the script below which report is exceeded records in ServiceNow all table which extend from task table.

var gr = new GlideRecord('task');

gr.addQuery('glidefunction:length(short_description)>250');
gr.query();

gs.info(gr.getRowCount());

while(gr.next()){

gs.info(gr.number);

}