Tong Sun wrote:
JMeter has a built-in variable ${__jm__Thread Group__idx} to retrieve the
current iteration, and I want to replace the `Thread Group`
using ${__threadGroupName}. So this comes natural to me:

"Iteration Number is ${__V(__jm__${__threadGroupName}__idx)}"

But when I try it, I always get "0".

What's wrong with it and what's the fix pls? thx

It comes natural to you only. If you open JSR223 Sampler <https://jmeter.apache.org/usermanual/component_reference.html#JSR223_Sampler> documentation you will see something like:

The JSR223 test elements have a feature (compilation) that can significantly increase performance. To benefit from this feature:

  * Use Script files instead of inlining them. This will make JMeter
    compile them if this feature is available on ScriptEngine and
    cache them.
  * Or Use Script Text and check Cache compiled script if available
    property.
    When using this feature, ensure your script code does not use
    JMeter variables or JMeter function calls directly in script code
    as *caching would only cache first replacement*. Instead use
    script parameters.


So either put the functions combination into "Parameters" section of your "script" and use it like

"Iteration number is " + Parameters

or go for code-based equivalent:

"Iteration number is: " + vars.get('__jm__' + ctx.getThreadGroup().getName() + '__idx')

Check out Top 8 JMeter Java Classes You Should Be Using with Groovy <https://www.blazemeter.com/blog/jmeter-java-classes> to learn what do these *vars* and *ctx* guys mean.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@jmeter.apache.org
For additional commands, e-mail: user-h...@jmeter.apache.org

Reply via email to