2
votes

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
any feedback on my answer ? if it was helpful it should be accepted and possibly upvoted so that it's helpful to othersUBIK LOAD PACK

2 Answers

2
votes

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"));
0
votes

Do this:

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