Add encoded query

sigmachiuta
Kilo Guru

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();

 

10 REPLIES 10

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!


randrews
Tera Guru

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.


waseem5
Kilo Expert

This is what talk about adding encoded query



Encoded Query Strings - ServiceNow Wiki


tony_barratt
ServiceNow Employee
ServiceNow Employee

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.


  1. Open a list of records.
  2. Construct the filter.
  3. Click Run.
  4. Right-click the end of the filter breadcrumbs and select Copy query from the context menu.


     


    Selecting Copy query

  5. Use your computer's keyboard copy command to copy the query in the dialog box to your system clipboard.


     


    Copy the query to your computer's clipboard

  6. Click OK to close the dialog box.
  7. 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


hermanwinkel
Giga Contributor

Im also missing the line



gr.query();