Do we have LIKE / NOT LIKE conditions in ServiceNow to use in Scripting ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2016 02:03 AM
Hi,
Do we have LIKE/NOT LIKE conditions which can be used in add Query of the script. ? Just like below in SQL:
SELECT * FROM Customers
WHERE Country NOT LIKE '%land%';
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2016 02:22 AM
Hello sarvamangala,
Actualy to achieve this you can use:
var gr = new GlideRecord('CUSTOMERS');
gr.addQuery('country', 'DOES NOT CONTAIN', 'land');
gr.query();
while(gr.next()){
// Results....
}
Take a look at: Using GlideRecord to Query Tables - ServiceNow Wiki
Regards,
Michal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2016 03:50 AM
Can we use just an input parameter to check for 'CONTAINS/DOES NOT CONTAIN' function.
Exp:
gr.addQuery('country',DOESN NOT CONTAIN', input_parameter); // input_parameter is the value which is being passed from web services , so its not constant.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2016 03:55 AM
Yes,
but that depends on how you got this parameter, lets say:
var Your_parameter = Whatever_way_you_retrieve_it
Your_parameter = Your_parameter.toString();
var gr = new GlideRecord('CUSTOMERS');
gr.addQuery('country',DOESN NOT CONTAIN', Your_parameter);
gr.query();
while(gr.next()){
}
Regards,
Michal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2023 08:39 AM
In case anyone comes here looking for the info and finds the wiki links down:
https://servicenowguru.com/scripting/gliderecord-query-cheat-sheet/
Regards,
N.