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

tltoulson
Kilo Sage

You should be able to accomplish this with the following encoded query:



gr.addEncodedQuery('u_configuration_itemIN' + current.u_configuration_item.toString());


Travis is correct though I also noticed you have another addQuery for state as well.   You will need to combine all of those into the 1 addEncodedQuery statement:


gr.addEncodedQuery('state=2^u_configuration_itemIN' + current.u_configuration_item.toString());


Good catch, Michael Ritchie, I didn't even notice that.   Unless you have a particular preference for keeping them separate, I would go with Michael's approach.   I find its easier to read and edit a query if you avoid mixing addQuery and addEncodedQuery.


For some reason this script is still matching CI events that are not in an active maintenance mode.   How can i tell why this script is matching those events and changing the state to 3?