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

Beata I_owiecka
Kilo Guru

Hi Alon,

try this:

bs.addQuery('name=' + user);
bs.addQuery('u_allowed_duplication', 'CONTAINS', 'be3db45f0f0a0200883347bce1050e41');

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.

Pavankumar_1
Mega Patron

Hi,

if it possible with addQuery go with it because easy to understand.

for your requirement try this.

bs.addQuery('name', user); //if Operator is blank it will take it as =
bs.addQuery('u_allowed_duplication', 'CONTAINS', product); //you get product sysid on it pass it or use current.product

 

Hope you it helps you.

Please Mark Correct/helpful if applicable, Thanks!! 

 

Regards

Pavankumar

 

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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Brad has already mentioned the approach.

Did you try to check that?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader