how to use LIKE in query

Alon Grod
Tera Expert

Hi, 

I have this query and instead of using LIKE and sysid i need to use LIKE and the var product.

What is the right way to replacing the sys ID with the variable product?

u_allowed_duplication is of a type list and its a reference to a table, so i need to filter using contains which is LIKE.

bs.addEncodedQuery('name=' + user + ^u_allowed_duplication_swLIKEda1d2ffc1b3db05073542f02604bcbcb')

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

Hi Aon,

To replace the hard-coded sys_id with a variable depends on where you are running this script, but generally the syntax is current.variables.variable_name, so you can do this with an encoded query:

bs.addEncodedQuery('name=' + user + '^u_allowed_duplication_swLIKE' + current.variables.product);

or 2 addQuery lines:

bs.addQuery('name', user);
bs.addQuery('u_allowed_duplication', 'CONTAINS', current.variables.product);

both of these examples assume 'user' is defined elsewhere in the script.

View solution in original post

5 REPLIES 5

Pavankumar_1
Mega Patron

Hi @Alon Grod,

It is strange to me without checking the responses you or someone are marking the question as correct/helpful.

Please make sure validate the responses and mark only which you tried or which are helpful otherwise how this thread will help others and you as well.

There is no use if anyone marks the helpful as comments and try to hit helpful or accept the solution.

 

Regards

Pavankumar

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar