Add encoded query
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2015 11:43 AM
I have created a CI field that is a list. How can i write an encoded query to change the line that is not working below to an encoded query are both the queries on line 5 and 6 the same? I am trying to match a CI that is in a list.
if (current.u_configuration_item != "") {
var gr = new GlideRecord('u_maint');
//gr.addQuery('u_configuration_item','IN', current.u_configuration_item); This line is not working correctly
gr.addEncodedQuery(u_configuration_item>=current.u_configuration_item); Switch the above query out with an encoded query
gr.addQuery('state', 2);
if (gr.next()) {
current.u_event_state = 3;
current.update();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2015 12:18 PM
Hi Sigmachiuta,
Since you are using custom tables an columns I can't tell for sure why this isn't working. If u_configuration_item is a reference field maybe you are comparing the name of the CI with the sys_id. To make sure you are comparing the correct value I would suggest you to do a gs.print(current.u_configuration_item), if it print the sys_id then there is the problem.
Good Luck!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2015 12:28 PM
all of these suggestions are good... now let me tell ya the cheat... <grin>
look at the list view of the table you are querying... and use the condition builder to build the list EXACTLY the way you want it...
now right click the LAST breadcrumb and choose "Copy Query" copy the contents of the popup and put them in your encoded query....
saves a LOT of time doing it that way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2015 10:56 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2015 02:40 AM
Hi Waseem,
Good point, you are right. Specifically this section:
Encoded Query Strings - ServiceNow Wiki
..
3 Generating Encoded Query Strings through a Filter
You can generate an encoded query string through a filter on any list and paste the string into a URL query or a reference qualifier.
- Open a list of records.
- Construct the filter.
- Click Run.
- Right-click the end of the filter breadcrumbs and select Copy query from the context menu.
- Use your computer's keyboard copy command to copy the query in the dialog box to your system clipboard.
- Click OK to close the dialog box.
- Use the query string to construct a URL or an advanced reference qualifier.
3.1 Using the CONTAINS Operator
When you use the CONTAINS operator on a list filter, the system translates the filter to a LIKE query. For example, if you filter for active records with numbers that contain 123, the URL is https://InstanceName.service-now.com/incident_list.do?sysparm_query=active%3Dtrue%5EGOTOnumberLIKE12...
Best Regards
Tony
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2016 12:22 AM
Im also missing the line
gr.query();