EncodedQuery Issue

agulati
Kilo Expert

Hi,

I am using following code to run a EncodedQuery

  var incquery = new GlideRecord('incident');

  incquery.addEncodedQuery('active%3Dtrue^state<6^NQactive%3Dtrue');

  incquery.query();

  if (incquery.next())

  {

 

  }

and i do get the following error.

ava.lang.NullPointerException: java.lang.NullPointerException: com.glide.db.conditions.MultipleCondition.processQuery(MultipleCondition.java:98) com.glide.db.conditions.MultipleCondition.toSQLBuffer(MultipleCondition.java:80) com.glide.db.conditions.QueryCondition.toSQLBuffer(QueryCondition.java:401) com.glide.db.DBQuery.whereClause0(DBQuery.java:1340) com.glide.db.DBQuery.toSQL(DBQuery.java:728) com.glide.db.DBQuery.getSelectStmt(DBQuery.java:629) com.glide.db.DBQuery.executeAsResultSet0(DBQuery.java:243) com.glide.db.DBQuery.executeAndReturnTable(DBQuery.java:229) com.glide.db.DBAction.executeNormal(DBAction.java:204) com.glide.db.DBAction.executeAndReturnException(DBAction.java:167) com.glide.db.RDBMSQueryContext.executeQuery(RDBMSQueryContext.java:46) com.glide.db.DBQuery.execute(DBQuery.java:1735) com.glide.db.meta.Table.queryBasic(Table.java:292) com.glide.db.meta.Table.query(Table.java:189) com.glide.script.GlideRecordITable.query(GlideRecordITable.java:76) com.glide.script.GlideRecord.query0(GlideRecord.java:2828) com.glide.script.GlideRecord.query(GlideRecord.java:2598) com.glide.script.GlideRecord.jsFunction_query(GlideRecord.java:2484) inv7.invoke() org.mozilla.javascript.FunctionObject.doInvoke(FunctionObject.java:565) org.mozilla.javascript.FunctionObject.call(FunctionObject.java:480) org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1201) org.mozilla.javascript.gen.c2418.call(<refname>:4) org.mozilla.javascript.gen.c2418.exec(<refname>) com.glide.script.ScriptEvaluator.execute(ScriptEvaluator.java:162) com.glide.script.ScriptEvaluator.execute(ScriptEvaluator.java:176) com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:68) com.glide.script.Evaluator.evaluateString(Evaluator.java:161) com.glide.script.Evaluator.evaluateString(Evaluator.java:156) com.glide.processors.ScriptProcessor.evaluateScript(ScriptProcessor.java:282) com.glide.processors.ScriptProcessor.runScript(ScriptProcessor.java:201) com.glide.processors.ScriptProcessor.process(ScriptProcessor.java:159) com.glide.processors.Processor.runProcessor(Processor.java:358) com.glide.processors.Processor.processTransaction(Processor.java:163) com.glide.processors.ProcessorRegistry.process(ProcessorRegistry.java:146) com.glide.ui.GlideServletTransaction.process(GlideServletTransaction.java:36) com.glide.ui.GlideServlet$1.run(GlideServlet.java:408) java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) java.lang.Thread.run(Thread.java:682)

Any pointers?

-Aman

1 ACCEPTED SOLUTION

Anthony_vickery
Tera Expert

Hi Aman,


Your encoded query appears to be partially escaped and is probably being ignored, though I'm not certain why the NullPointerException and not just a full incident query. You could replace those occurrences of %3D with =


Or alternatively unescape the encoded query string


  incquery.addEncodedQuery('active=true^state<6^NQactive=true');



or



  incquery.addEncodedQuery(unescape('active%3Dtrue^state<6^NQactive%3Dtrue'));


View solution in original post

3 REPLIES 3

Anthony_vickery
Tera Expert

Hi Aman,


Your encoded query appears to be partially escaped and is probably being ignored, though I'm not certain why the NullPointerException and not just a full incident query. You could replace those occurrences of %3D with =


Or alternatively unescape the encoded query string


  incquery.addEncodedQuery('active=true^state<6^NQactive=true');



or



  incquery.addEncodedQuery(unescape('active%3Dtrue^state<6^NQactive%3Dtrue'));


Hi Anthony,


Thanks for the reply. I tried that before adding the post and that is the only way to solve the issue.



-Aman


tony_barratt
ServiceNow Employee
ServiceNow Employee

Hi Aman,



If you want to use an encoded query it is a good idea to build the query in a list view and copy it.


For example:


Screen Shot 2016-05-22 at 6.57.51 AM.JPG



active=true^state<6^ORactive!=true



This means the the syntax is always correct plus you can check the logic is in line with what you want to achieve by looking at the result set.



Best Regards



Tony