I have two following arrays (note: given array is a sample part of the original array as it have more than 2K values).
parsedResultBD = [accounts:[
[name: "Perf", uuid: "17e9b276-081a-11ee-be56-0242ac120002"],
[name: "MIB01", uuid: "1cd21e7c-081a-11ee-be56-0242ac120002"],
[name: "MIB02", uuid: "203be7e6-081a-11ee-be56-0242ac120002"],
[name: "Inflammation", uuid: "234d02b2-081a-11ee-be56-0242ac120002"],
[name: "MIB03", uuid: "26e7f56c-081a-11ee-be56-0242ac120002"],
[name: "Test_Study", uuid: "2a2517be-081a-11ee-be56-0242ac120002"]],
status: 'OK',
page: [rows: 5000, more: 0, number: 1]]
and
filteredStudyName = ["Inflammation","Perf","Test_Study"]
Want to add the UUID from parsedResultBD
to an empty array which have the name same in filteredStudyName
. The code is printing the UUID but while adding I am getting,
2023-06-11 11:06:12,362 INFO o.a.j.e.J.StudyName_Processer: UUID : 17e9b276-081a-11ee-be56-0242ac120002
2023-06-11 11:06:12,363 INFO o.a.j.e.J.StudyName_Processer: UUID : 234d02b2-081a-11ee-be56-0242ac120002
2023-06-11 11:06:12,363 INFO o.a.j.e.J.StudyName_Processer: UUID : 2a2517be-081a-11ee-be56-0242ac120002
2023-06-11 11:06:12,363 ERROR o.a.j.e.JSR223PostProcessor: Problem in JSR223 script, StudyName_Processer
javax.script.ScriptException: javax.script.ScriptException: java.lang.IllegalArgumentException: wrong number of arguments
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:158) ~[groovy-jsr223-3.0.11.jar:3.0.11]
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:231) ~[java.scripting:?]
at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:219) ~[ApacheJMeter_core.jar:5.5]
at org.apache.jmeter.extractor.JSR223PostProcessor.process(JSR223PostProcessor.java:45) ~[ApacheJMeter_components.jar:5.5]
at org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:968) ~[ApacheJMeter_core.jar:5.5]
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:585) ~[ApacheJMeter_core.jar:5.5]
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:501) ~[ApacheJMeter_core.jar:5.5]
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:268) ~[ApacheJMeter_core.jar:5.5]
at java.lang.Thread.run(Thread.java:833) ~[?:?]
Code Block:
def bdConverter = new JsonSlurper();
def responseBDTemp = prev.getResponseDataAsString();
def responseBD = bdConverter.parseText(responseBDTemp);
def resultStudyUUIDCollector = [];
def parsedResultBD = responseBD.accounts;
def filteredStudyName = ["Inflammation","Perf","Test_Study"]
parsedResultBD.each {
entryVal ->
for (tempValueOfStudy in filteredStudyName) {
if (tempValueOfStudy == entryVal.name) {
log.info('UUID : ' + entryVal.uuid);
resultStudyUUIDCollector.add(entryVal.uuid as String);
resultStudyUUIDCollector << entryVal.uuid; //tried with this also getting similar error
}
}
}
log.info(resultStudyUUIDCollector)
What I am doing wrong here ?
You could do something like:
def emptyArray = []
filteredStudyName.each { name ->
emptyArray.add(parsedResultBD.accounts.find { account -> account.name == name }.uuid)
}
Full code snippet from your question data just in case:
def parsedResultBD = [accounts: [
[name: "Perf", uuid: "17e9b276-081a-11ee-be56-0242ac120002"],
[name: "MIB01", uuid: "1cd21e7c-081a-11ee-be56-0242ac120002"],
[name: "MIB02", uuid: "203be7e6-081a-11ee-be56-0242ac120002"],
[name: "Inflammation", uuid: "234d02b2-081a-11ee-be56-0242ac120002"],
[name: "MIB03", uuid: "26e7f56c-081a-11ee-be56-0242ac120002"],
[name: "Test_Study", uuid: "2a2517be-081a-11ee-be56-0242ac120002"]],
status : 'OK',
page : [rows: 5000, more: 0, number: 1]]
def filteredStudyName = ["Inflammation", "Perf", "Test_Study"]
def emptyArray = []
filteredStudyName.each { name ->
emptyArray.add(parsedResultBD.accounts.find { account -> account.name == name }.uuid)
}
log.info('Generated array: ' + emptyArray)
More information: