Thanks.

So the root cause is:

> ensure your script code does not use
>     JMeter variables or JMeter function calls directly

Having known that, I still don't quite understand why I'm getting zeros.
My actual groovy string is:

"ThreadGroup: ${__threadNum}, Iteration Number:
${__V(__jm__${__threadGroupName}__idx)}"

Now, suppose `${__threadGroupName}` returns `My_TG`, then the
`${__V(__jm__${__threadGroupName}__idx)}` will become
`${__jm__My_TG__idx}`, right? Then why ${__threadNum} gives none zero,
while ${__jm__My_TG__idx} always gives zero pls? They are the same built-in
JMeter variables and should behave the same way, right?



On Tue, Apr 2, 2024 at 1:09 PM Dmitri T <glin...@live.com> wrote:

> 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.
>
>

Reply via email to