Search code examples
jmeterbeanshell

Put value in parameter using beanshell and jmeter


I have a question about a very basic script that I wrote, I just want to get data from DB, put it in a variable using beanshell sampler. and in the end of the thread group to create another bean shell and check the value of this variable.

the problem is at saving the data to a variable (var name is before), when I use the props.put command but the value still null.

Can someone please advise?

enter image description here

enter image description here


Solution

  • If you want to store a value into JMeter Variables you should amend your code like:

    vars.put("before", String.valueOf("budgetInt"))
    System.out.println("Before is " + vars.get("before"));
    

    Once done you should be able to access the defined variable as ${before} or ${__V(before)} where required.

    If you amend your property setting like:

    props.put("Before", String.valueOf(budgetInt))
    

    You should be also able to access the value as ${__P(Before,)}

    Also consider switching to JSR223 Sampler and Groovy language.