1. You don't need to use __evalVar() function in Groovy, in general
inlining JMeter Functions and Variables into scripts is not the best
idea as only first occurrence will be cached
<https://jmeter.apache.org/usermanual/component_reference.html#JSR223_Sampler>
so you will have the same query for all iterations even if the
values will be changing.
2. If you want to utilize Groovy's string interpolation
<https://groovy-lang.org/syntax.html#_string_interpolation> feature
you need to use double quotation marks
<https://groovy-lang.org/syntax.html#_double_quoted_string> like
"select ${column} from ${table}"
3. "column" and "table" variables need to be defined *before* declaring
the "query" variable
Suggested code change:
column="name"
table="customers"
query="select ${column}from ${table}"
log.info("${query}")
More information on Groovy scripting in JMeter - Apache Groovy: What Is
Groovy Used For? <https://www.blazemeter.com/blog/apache-groovy>
On 9/4/2022 10:31 PM, Tong Sun wrote:
Hi,
Fromhttps://jmeter.apache.org/usermanual/functions.html#__evalVar
__evalVar
The evalVar function returns the result of evaluating an expression stored
in a variable.
This allows one to read a string from a file, and process any variable
references in it. For example, if the variable "query" contains "select
${column} from ${table}" and "column" and "table" contain "name" and "
customers", then ${__evalVar(query)} will evaluate as "select name from
customers".
However, I tried it (in JM5.5), but wasn't able to make it work:
query = '''select ${column} from ${table}'''
column = "name"
table = "customers"
log.info("${query}")
log.info('=${__evalVar(query)}=')
but the output I got is:
select ${column} from ${table}==
How to make it work please?