'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:36 PM
Is this a client script or a business rule? Tough to tell from this context. If it's a client script, then addEncodedQuery() is not available. If it's a business rule (or any server side script like scripts background), then alert() is not available.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2016 01:39 PM
It is in the "Client Script" section of a UI Page
And sorry to not reply - the space did not work...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2016 01:43 PM
Thanks for the clarification Josh. Is the script starting at all? Can you put in some statements to see how far through it is getting? What are the results of
alert(scSearch.getRowCount() + ' rows');
after
scSearch.query()?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2016 01:50 PM
This query returns what I expect it to when I search the word Apple:
//query for service catalog items
alert('1');
var scSearch = new GlideRecord('sc_cat_item');
alert('2');
scSearch.addQuery('active', 'true');
alert('2');
scSearch.addQuery('u_tag', 'CONTAINS', searchParameters);
alert('3');
scSearch.setLimit(5);
alert('4');
scSearch.orderByDesc('sys_updated_on');
alert('5');
scSearch.query();
alert('6');
while(scSearch.next())
{
alert('found query results');
}
This query does not return anything, but should return what the above query did I believe when I search Apple:
//query for service catalog items
alert('1');
var scSearch = new GlideRecord('sc_cat_item');
alert('2');
scSearch.addQuery('active', 'true');
alert('2');
scSearch.addQuery('u_tag', 'IN', searchParameters);
alert('3');
scSearch.setLimit(5);
alert('4');
scSearch.orderByDesc('sys_updated_on');
alert('5');
scSearch.query();
alert('6');
while(scSearch.next())
{
alert('found query results');
}
Both of these hit all alerts in query, but only the top one hits the while loop alert.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2016 01:55 PM
Silly question... what is the field type on u_tag?
CONTAINS is going to do something different than IN. IN uses a set, like a few, but not all choice list values.
LIKE does a string comparison with the string.
What is a sample of something you would find in u_tag?