I want to define a variable in User Defined Variables and use it in the same config element later. I've tried for just defined smoke variable to add below it another line with value:
${__javaScript(${smoke} > 0 ? 10 : 100)}

1st line gives ${smoke} not defined error in log, 2nd line produces 2 always (smoke == 1 or 0).

I know workaround of defining property, however, could my goal be achived by just variables and if yes, than how?

1 Answer 1


As per User Defined Variables documentation:

the variables are not available for use until after the element has been processed, so you cannot reference variables that are defined in the same element. You can reference variables defined in earlier UDVs or on the Test Plan.


UDVs should not be used with functions that generate different results each time they are called. Only the result of the first function call will be saved in the variable

So if you really want to go this way make sure to define your ${smoke} variable in another User Defined Variables

In general you don't even need to use the User Defined Variables, __javaScript() function has second argument which can be used for storing evaluation result in an arbitrary JMeter Variable:

enter image description here

Since JMeter 3.1 users are encouraged to use scripting language which provides maximum performance, as of JMeter 5.1 you should be using __groovy() function where possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.