1

So I have 2 JSR223 samplers in Jmeter Thread Group.
In the first one, I declare an empty array list

import java.util.List;
import java.util.ArrayList;

myList = new ArrayList();

In the second JSR223 Sampler, that is inside ForEach Controller, I am trying to access myList variable in order to add some value

import java.util.List;
import java.util.ArrayList;

myList.add(vars.get('trace_id'));

I keep getting the message

Response message: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: myList for class: Script468

I was reading this (not official Jmeter docs though) and it says that By default, creating any new variables are local to a thread. It can not be accessed by other threads in the same thread group / other thread groups in the Test plan. so I was thinking I do everything right.

Is it possible to access the variable declared in one groovy sampler (JSR223) in another JSR223 sampler or I am trying to achieve not feasible scenario here?

TiredOfProgramming
  • 845
  • 2
  • 16
  • 41

1 Answers1

3

to do that, in first JSR223 Sampler add this:

vars.putObject("myList", myList);

In second one:

def myList = vars.getObject("myList");

See javadocs:

UBIK LOAD PACK
  • 33,980
  • 5
  • 71
  • 116