'IN' GlideRecord Query Not Working as Expected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2016 01:09 PM
I have a query that I have written that is looking at a Tag field on the sc_cat_item table. This Tag field is a comma delimited field, for instance it would look like this (apple, laptop, desktop, hp, hardware).
My query looks like this:
var searchParameters = document.getElementById("searchParams").value;
var myNewStr = searchParameters.replace(/ /g,', ');
var scSearch = new GlideRecord('sc_cat_item');
scSearch.addQuery('active', 'true');
scSearch.addQuery('u_tag', 'IN', myNewStr );
scSearch.setLimit(5);
scSearch.orderByDesc('sys_updated_on');
scSearch.query();
If I were to type in "this is my apple" The myNewStr returns this "this, is, my, apple" and I would expect the query to return 1 result, because 1 catalog item has a tag that is named apple.... but it is returning 0 results, why is it not returning anything?
Am I misinterpreting the IN in GlideRecord? I also used CONTAIN and it did not work either...
Any advice?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2016 01:57 PM
u_tag is a string field type
an example of something in that field would be:
apple, excel, word, desktop, laptop

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2016 02:05 PM
OK. Thanks for the sample data and clarification. Whew. If that's the case, then "CONTAINS" is your best candidate for the query operator on u_tag.
Did getRowCount() respond with anything?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2016 01:36 PM
Based on my alerts it is throwing the error on this line:
scSearch.addEncodedQuery(scQueryString);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2016 01:44 PM
Josh,
addEncodedQuery() method is not available on client side. Use addQuery() instead.
Thanks,
Abhinay
Please mark Helpful, Like, or Correct depending on the impact of the response

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2016 02:51 PM
Hi Josh,
I think you would need to look at splitting your search string (myNewStr) into an array first, and then query on the values using OR conditions. The problem I see occurring as you have it now, is that as soon as you have multiple values stored in u_tag, then your search string will have to replicate the order exactly in order to match.
i.e.,
- if u_tag = "apple, fruit", then searching for:
- "Show all my fruit apple" will NOT match
- "Show all my apple fruit" will match
- "Show all my apple" will NOT match
Because you will be querying for a u_tag value of "apple, fruit" contained IN "show, all, my, apple" (etc.)
Hope that makes sense...
-Brian