Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Query List Field for only exact matches

barcar
Tera Contributor

Looking for any suggestions to solve this puzzle...

I have a table with a List collector field which has a choice list based on the sys_user employee_type - so it's stored as a string with a list like "employee,contactor,vendor".

I want to query this table to see find a record containing a match for a specific employee type.

If I query with addQuery("employee_types","CONTAINS","employee") then I get the expected row but also get substring matches for our "Non-employee" employee type.

Is there a way via a regular GlideRecord query to make this only match on full list values or am I going to have to look through the returned records from the query and apply a regex match?

3 REPLIES 3

Willem
Giga Sage
Giga Sage

I think your best bet is indeed to "look through the returned records from the query and apply a regex match".

 

If the employee type cannot contain both at the same time however, you can exclude values in your query like so:

gr.addQuery("employee_types","CONTAINS","employee");

gr.addQuery("employee_types","DOES NOT CONTAIN","Non-employee");

barcar
Tera Contributor

Thanks Willem - I was hoping for something I could do in the UI query filter too. But I guess I'll revert to looping through the list.

asifnoor
Kilo Patron

I don't think there is any option in Gliderecord query to do this.

You can loop through and can check like this

var arr = gr.your_list.toString().split(",");

if(arr.indexOf("employee") >-1) {

}

Mark the comment as a correct answer and also helpful if it helps to solve the problem.