"Does not end with" operator

gerald_c
Kilo Explorer

Hi there,

I'm trying to query a list of records which requires "does not end with" operator. Is there such operator? If not, what would be a workaround?

For example:

var db = new GlideRecord('table');

if X = 1 then

db.addQuery("field", "ENDSWITH", "5")

else

db.addQuery("field", "DOES NOT END WITH", "5")

2 REPLIES 2

coryseering
ServiceNow Employee
ServiceNow Employee

Hi Gerald,



That's not an available operator. Depending on the size of the table, you could find all records where the field ends with that string. Store the sys_ids, then query for all records that contain that string, and filter out any that where the sys_id was one you found already.



If the table is very large, the queries will be slow and memory-intensive. What is the actual business case you are trying to solve? There may be a better way to go about this.


Hi Cory,



We have a list of items that users can select on a page. Based on the answer that they gave a previous step, this list will be restricted accordingly. I used the following syntax. It's not ideal but it will do for now. This is only a hot fix for now, as it will be changed properly in a later release. I will keep your idea in mind though.



if X = 1 then


db.addQuery("field", "ENDSWITH", "5")


else


var qry = db.addQuery("field", "ENDSWITH", "1");


qry.addOrCondition("field", "ENDSWITH", "2");


.


.


.


qry.addOrCondition("field", "ENDSWITH", "9");


qry.addOrCondition("field", "ENDSWITH", "0");