0
votes

In documentation mentioned that to see/pass variable content we should use

var2 = vars.get("var1");

I created a script and tried to use this get function and the value is null, when I printed the value of the "source" variable I see its value, can someone please explain? (as you can see when I print using get I see NULL returned)

Moreover can someone please fully explained (with PIC if I may ask) how to call var2 in a second sampler, I am facing an issues with variables in groovy and read the DOCs

documantation

enter image description here

enter image description here

2

2 Answers

2
votes

vars.get can handle only String and not other objects as Integer,

You need to put the value of Integer using putObject, First groovy:

def old_budget = 137000000
vars.putObject("old_budget", old_budget);

You need to put the value of Integer using getObject, Second groovy:

def old_budget = vars.getObject("old_budget");
log.info(String.valueOf(old_budget));
1
votes

vars is a shorthand to JMeterVariables class instance, see the JavaDoc for all available methods and fields.

If your var1 is not null and it is a String you code should work normally. Demo:

JMeter JSR223 Accessing Variables

In case of any problems check out jmeter.log file for any suspicious entries, you should be able to figure out the cause of your Groovy script failure from there.

Going forward always include your full code as well as the relevant jmeter.log file entries, preferably in form of text, not images.

See Groovy Getting Started and Apache Groovy - Why and How You Should Use It guides for more information on Groovy scripting in general and in the context of JMeter scripts.