Is there a wildcard character to use for the rest api/table api?

James Rac
Tera Contributor

Hi all,

I'm using the rest api to search on contacts by phone number, but the phone number format can be widely varied. Because of this, sometimes the query fails if it is not an exact match. I found some documentation regarding wildcards for the global search but nothing for the api. I've tried the same characters for the api with no luck, the * or % characters. Is this something that is supported with the api or is it not available?

 

Ideally I'd be able to do something like *1*123*123*1234 to match all forms of different phone number formats such as 1 (123) 123 1234, 1 (123)-123-1234, 1 123-123-1234, +11231231234

I saw some suggestions to make another field and do a format on it and then run my query against this field... I dont think that would work for me. I would preferably like to not create a custom field just to search on this one phone number field, since the alternative means creating custom fields for every phone number field I want to query on...

 

Thanks.

5 REPLIES 5

James Chun
Kilo Patron

Hi @James Rac,

 

You can use an encoded query to fetch all the records that match a condition.

e.g.

JamesChun_0-1712717986884.png

Note that I am querying on the [sys_user] table where the user name contains Alex.

This will return 3 records like below:

JamesChun_1-1712718045227.png

 

You should be able to do the same for your contact query with slight adjustments.

 

Hope it helps, cheers

 

Amit Verma
Kilo Patron
Kilo Patron

Hi @James Rac 

 

Below post could be helpful :

https://www.servicenow.com/community/developer-forum/is-there-a-way-to-do-a-like-query-using-the-res...

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

James Rac
Tera Contributor

hi @James Chun & @Amit Verma,

 

I read this post already in search of my answer. The problem with these answers in this post would only apply if I did partial searches on the phone number variable. For things like the operating system looking for any windows/linux/etc, this makes sense, but for phone numbers, if I know the full number but I just want to account for multiple us/international formats, doing a like with a partial query doesn't in my opinion.

Thanks for the quick responses however, it is appreciated. I'm open for any other ideas. 🙂

Amit Pandey
Kilo Sage

Hi @James Rac 

 

You can construct a regex pattern that matches various phone number formats and then store in your field. For example, the regex pattern \b1(?:[.-]?[0-9]){10}\b would match phone numbers like 1 (123) 123 1234, 1-(123)-123-1234, etc.

 

Regards,

Amit