escaping special characters in search

IanGlencross
Kilo Expert

My LDAP is occasioanlly putting some junk into my sys_user table.   In particular it is inserting a carat (^)   character every now and again.

I was hoping to do a quick search for the carat (^)   character but search won't do it, neither will the URL based   https://<BASE>.service-now.com/sys_user_list.do?sysparm_query=user_nameLIKE^   as service now uses ^ as a logical "and".   I have to tried encode ( %5E) but this has no effect.

How do I escape this charater (and other special characters) in either of these scenarios?   Or do I need to write some regex ( /^\S*\^\S*$/) and run it in a script?

1 ACCEPTED SOLUTION

1
2
3
4
5
6
7
var rec = new GlideRecord('sys_user');
rec.addQuery('user_name', "CONTAINS", "^");
rec.query();
while (rec.next()) { 
var str = 'Found user with carat: ' + rec.user_name + '          sys_id: ' + rec.sys_id;
 gs.print(str);
}


(Better formatting...)


View solution in original post

5 REPLIES 5

BenPhillipsSNC
Kilo Guru

Hi Ian



No amount of encoding seems to be working for the caret in the sysparm filter. Good news though, it does work in GlideRecord! Try running this in the "Scripts - Background" module. This worked for me:



var rec = new GlideRecord('sys_user');rec.addQuery('user_name', "CONTAINS", "^");rec.query();while (rec.next()) { 
var str = 'Found user with carat: ' + rec.user_name + '     sys_id: ' + rec.sys_id;gs.print(str);}

1
2
3
4
5
6
7
var rec = new GlideRecord('sys_user');
rec.addQuery('user_name', "CONTAINS", "^");
rec.query();
while (rec.next()) { 
var str = 'Found user with carat: ' + rec.user_name + '          sys_id: ' + rec.sys_id;
 gs.print(str);
}


(Better formatting...)


That would be for the cleanup of users already on your user table. Going forward, you will definitely want to clean that out of your incoming data before committing to your users table by putting in a field script on your ldap import transform map.   Transform Map Scripts - ServiceNow Wiki



Hope that helps!



Thanks


Thanks for the tip Ben.


I'm already working through the Transform Map with the LDAP process, as it has other issues as well.   <Sigh>   The team / person who developed this did not document or comment anything, and it doesn't look like its been looked at since Aspen/Berlin.