variable is assigned a null value in jmeter beanshell sampler

3.6k Views Asked by At

Hi I am trying to assign value extracted from one sampler to another variable in a beanshell script. I have the below beanshell script.

  vars.put("linkArr",vars.get("${PlanLinksArray_1}"));

the text request in jmeter is showing the below for beanshell sampler

vars.put("linkArr",vars.get("9PacMiSVl6GIQAtco747NQ"));

but the linkArr variable is showing a null value in the debug sampler.

why is that i am getting a null value when I am expecting 9PacMiSVl6GIQAtco747NQ value to be assigned to the linkArr variable. please suggest

beanshell request shown below

debug sampler result for linkArr shown below

2

There are 2 best solutions below

0
On

Do this:

vars.put("linkArr",vars.get("PlanLinksArray_1"));

0
On

You try to get the value of a variable named 9PacMiSVl6GIQAtco747NQ. As such variable doesn't exist, your vars.get returns null.

This is because

  1. The variable ${} gets resolved and becomes a string value.
  2. The beanshell function is executed and tries to get a variable with the in 1st resolved variable-name.

In general: Within beanshell ${} is almost never needed (except for very specific purposes).

Try this instead:

vars.put("linkArr",vars.get("PlanLinksArray_1"));