get a list of all the records which match the condition in ATF
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2024 09:08 PM - edited 03-15-2024 09:11 PM
Hi,
I have written a server side script in ATF to list the list of the records which match the encoded query condition. The records which match the condition are 110. I am unable to get the list of records. Please help me update the script. Kindly help.
(function(outputs, steps, params, stepResult, assertEqual) {
var gr = new GlideRecord("sn_vul_vulnerable_item");
gr.addEncodedQuery("active=true^risk_rating=2^vulnerability.v3_base_scoreISNOTEMPTY^ORvulnerability.v3_base_score!=0^vulnerability.v3_base_score>8.9");
gr.query();
while(gr.next()){
return true;
}
Regards
Suman P.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2024 05:18 AM
Hi @Community Alums,
Though I do not have the same table, I have replicated the issue by using the incident table. The scenario which I focused is "All active incidents with priority as 1 or 3" should be excluded and the rest count and incident number should be visible. Currently with "All active incidents with priority as 1 or 3" filter if i search table I could see 24 records matching. The below script helped me in getting the other tickets which do not match this filter.
var arr = [];
var brr=[];
var gr = new GlideRecord("incident");
gr.addEncodedQuery("active=true^priority=1^ORpriority=3"); // Filters
gr.query();
while (gr.next()) {
arr.push(gr.number.toString()); // Push incident numbers to the array so that we can exclude them in next run
}
var br= new GlideRecord("incident");
br.addEncodedQuery("numberNOT IN"+arr); //filtering all the numbers that matched our previous query
br.query();
while(br.next()){
brr.push(br.number.toString()); //Array of numbers that does not match our conditions
}
gs.print(brr.join(", "));
gs.print(brr.length);
By executing the mentioned script I was able to avoid the matching filtered numbers and print only the unmatched numbers. Please find the result in that attached screenshot.
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.
Thanks and Regards,
K. Sai Charan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2024 06:46 AM
Hi @Sai_Charan_K ,
I made some changes to meet my requirement. I am getting an error.
var arr = [];
var brr=[];
var gr = new GlideRecord("sn_vul_vulnerable");
gr.addEncodedQuery("active=true^risk_rating=2^vulnerability.v3_base_scoreISNOTEMPTY^ORvulnerability.v3_base_score!=0^vulnerability.v3_base_scoreBETWEEN7@8.9"); // Filters
gr.query();
while (gr.next()) {
arr.push(gr.number.toString()); // Push incident numbers to the array so that we can exclude them in next run
}
var br= new GlideRecord("sn_vul_vulnerable");
br.addEncodedQuery("numberNOT IN"+arr); //filtering all the numbers that matched our previous query
br.query();
while(br.next()){
brr.push(br.number.toString()); //Array of numbers that does not match our conditions
}
gs.print(brr.join(", "));
gs.print(brr.length);
Error:
Couldn't decipher the stack trace resulting from the following JavaScriptException:
java.lang.NullPointerException: org.mozilla.javascript.JavaScriptException: java.lang.NullPointerException: org.mozilla.javascript.Context.makeJavaScriptException(Context.java:2080)
org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:2066)
org.mozilla.javascript.MemberBox.invoke(MemberBox.java:143)
org.mozilla.javascript.FunctionObject.doInvoke(FunctionObject.java:677)
org.mozilla.javascript.FunctionObject.call(FunctionObject.java:614)
org.mozilla.javascript.ScriptRuntime.doCall(ScriptRuntime.java:2649)
org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1518)
org.mozilla.javascript.Interpreter.interpret(Interpreter.java:830)
org.mozilla.javascript.InterpretedFunction.lambda$call$0(InterpretedFunction.java:160)
com.glide.caller.gen.null_null_script.call(Unknown Source)
com.glide.script.ScriptCaller.call(ScriptCaller.java:22)
org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:159)
org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:597)
org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3573)
org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:172)
com.glide.script.ScriptEvaluator.execute(ScriptEvaluator.java:408)
com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:218)
com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:137)
com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:363)
com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:250)
com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:229)
com.glide.processors.ScriptProcessor.evaluateScript0(ScriptProcessor.java:399)
com.glide.processors.ScriptProcessor.lambda$evaluateScriptWithRecordingOption$0(ScriptProcessor.java:382)
com.glide.rollback.recording.RollbackRecorder.execute(RollbackRecorder.java:67)
com.glide.processors.ScriptProcessor.evaluateScriptWithRecordingOption(ScriptProcessor.java:382)
com.glide.processors.ScriptProcessor.evaluateScript(ScriptProcessor.java:362)
com.glide.processors.ScriptProcessor.runScript(ScriptProcessor.java:261)
com.glide.processors.ScriptProcessor.process(ScriptProcessor.java:219)
com.glide.processors.AProcessor.runProcessor(AProcessor.java:733)
com.glide.processors.AProcessor.processTransaction(AProcessor.java:291)
com.glide.processors.ProcessorRegistry.process0(ProcessorRegistry.java:187)
com.glide.processors.ProcessorRegistry.process(ProcessorRegistry.java:175)
com.glide.ui.GlideServletTransaction.process(GlideServletTransaction.java:58)
com.glide.sys.Transaction.run(Transaction.java:2645)
com.glide.ui.HTTPTransaction.run(HTTPTransaction.java:30)
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
java.base/java.lang.Thread.run(Thread.java:829)
JavaScript evaluation error on:
var arr = [];
var brr=[];
var gr = new GlideRecord("sn_vul_vulnerable");
gr.addEncodedQuery("active=true^risk_rating=2^vulnerability.v3_base_scoreISNOTEMPTY^ORvulnerability.v3_base_score!=0^vulnerability.v3_base_scoreBETWEEN7@8.9"); // Filters
gr.query();
while (gr.next()) {
arr.push(gr.number.toString()); // Push incident numbers to the array so that we can exclude them in next run
}
var br= new GlideRecord("sn_vul_vulnerable");
br.addEncodedQuery("numberNOT IN"+arr); //filtering all the numbers that matched our previous query
br.query();
while(br.next()){
brr.push(br.number.toString()); //Array of numbers that does not match our conditions
}
gs.print(brr.join(", "));
gs.print(brr.length);
Root cause of JavaScriptException: java.lang.NullPointerException
: java.lang.NullPointerException: com.glide.script.GlideRecord.addQueryString(GlideRecord.java:3041)
com.glide.script.GlideRecord.addQueryString(GlideRecord.java:3012)
com.glide.script.GlideRecord.js_addEncodedQuery(GlideRecord.java:2851)
jdk.internal.reflect.GeneratedMethodAccessor78.invoke(Unknown Source)
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.base/java.lang.reflect.Method.invoke(Method.java:566)
org.mozilla.javascript.MemberBox.invoke(MemberBox.java:138)
org.mozilla.javascript.FunctionObject.doInvoke(FunctionObject.java:677)
org.mozilla.javascript.FunctionObject.call(FunctionObject.java:614)
org.mozilla.javascript.ScriptRuntime.doCall(ScriptRuntime.java:2649)
org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1518)
org.mozilla.javascript.Interpreter.interpret(Interpreter.java:830)
org.mozilla.javascript.InterpretedFunction.lambda$call$0(InterpretedFunction.java:160)
com.glide.caller.gen.null_null_script.call(Unknown Source)
com.glide.script.ScriptCaller.call(ScriptCaller.java:22)
org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:159)
org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:597)
org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3573)
org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:172)
com.glide.script.ScriptEvaluator.execute(ScriptEvaluator.java:408)
com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:218)
com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:137)
com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:363)
com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:250)
com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:229)
com.glide.processors.ScriptProcessor.evaluateScript0(ScriptProcessor.java:399)
com.glide.processors.ScriptProcessor.lambda$evaluateScriptWithRecordingOption$0(ScriptProcessor.java:382)
com.glide.rollback.recording.RollbackRecorder.execute(RollbackRecorder.java:67)
com.glide.processors.ScriptProcessor.evaluateScriptWithRecordingOption(ScriptProcessor.java:382)
com.glide.processors.ScriptProcessor.evaluateScript(ScriptProcessor.java:362)
com.glide.processors.ScriptProcessor.runScript(ScriptProcessor.java:261)
com.glide.processors.ScriptProcessor.process(ScriptProcessor.java:219)
com.glide.processors.AProcessor.runProcessor(AProcessor.java:733)
com.glide.processors.AProcessor.processTransaction(AProcessor.java:291)
com.glide.processors.ProcessorRegistry.process0(ProcessorRegistry.java:187)
com.glide.processors.ProcessorRegistry.process(ProcessorRegistry.java:175)
com.glide.ui.GlideServletTransaction.process(GlideServletTransaction.java:58)
com.glide.sys.Transaction.run(Transaction.java:2645)
com.glide.ui.HTTPTransaction.run(HTTPTransaction.java:30)
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
java.base/java.lang.Thread.run(Thread.java:829)
Regards
Suman P.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2024 09:33 AM
Hi @Community Alums ,
Just wanted to know where are you using this script which you provided because gs.print is generally used to print data in background script which you have used somewhere which you shouldn't be using. Check where you are using and instead of gs.print use gs.log or gs.info
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.
Thanks and Regards,
K. Sai Charan