- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2022 04:25 AM
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')
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2022 05:10 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2022 04:48 AM
Hi Alon,
try this:
bs.addQuery('name=' + user);
bs.addQuery('u_allowed_duplication', 'CONTAINS', 'be3db45f0f0a0200883347bce1050e41');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2022 05:10 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2022 05:16 AM
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
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2022 06:47 AM
Hi,
Brad has already mentioned the approach.
Did you try to check that?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader