How to 'Does Not Start With' and 'Does Not End With' Operator in GlideRecord query - SOLVED
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2022 11:24 AM
How to 'Does Not Start With' and 'Does Not End With' Operator in GlideRecord query
The ServiceNow seems to not provide this functionality, but there is a way which is not documented.
We can still make use of SQL 'LIKE' and /or 'NOT LIKE' operator.
There is one limitation: All records with empty column where you perform 'NOT LIKE' condition are filtered out too.
Use Cases:
- Query all User groups [sys_user_group] with Name NOT starting on 'app' (not case sensitive)
var userGroupGR = new GlideRecord('sys_user_group');
userGroupGR.addQuery('name', 'NOT LIKE', 'app%');
userGroupGR.query();
gs.print(userGroupGR.getRowCount());
Verification: 'Number returned from script' + 'Count of records with Name starting with "app"' + 'Count of records with empty Name' = 'All Records count'
- Query all User groups [sys_user_group] with Name NOT ending on 'users' (not case sensitive)
var userGroupGR = new GlideRecord('sys_user_group');
userGroupGR.addQuery('name', 'NOT LIKE', '%users');
userGroupGR.query();
gs.print(userGroupGR.getRowCount());
Verification: 'Number returned from script' + 'Count of records with Name ending with "users"' + 'Count of records with empty Name' = 'All Records count'
- 3,831 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2024 05:03 AM
How to check for combination value.
for example : i need records with "name" column value (does not start with A- and end with -ADMIN)
example "A-servicwnow-Admin "
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2025 06:03 AM
Hi Revathy,
sorry, completely missed your post.
// Can't start with 'A_' and at the same time can't end with '-ADMIN'
var userGR = new GlideRecord('sys_user');
userGR.addQuery('name', 'NOT LIKE', 'A_%');
userGR.addQuery('name', 'NOT LIKE', '%-ADMIN');
userGR.query();