0

I have declared a range of indexed JMeter variables d1..dn.

Is there a way to operate with it within JS or Groovy script loop?

For instance I want to print all those variable, but I have problem with referring to them by name

for (i = 1; i<n; i++)
{
log.info(?)
}
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
  • I'm not sure why you would want to do this. What you are trying to do - while completely doable - is generally discouraged and (in most cases) can be done better in other ways. [See this answer](https://stackoverflow.com/a/8260202/2649853) on [this question](https://stackoverflow.com/questions/8260156/how-do-i-create-dynamic-variable-names-inside-a-loop/8260188?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa) for an approach you can use - Some other answers there suggest other methods (using arrays, for example) which may serve you better – Chirag Ravindra Jun 14 '18 at 09:18
  • Possible duplicate of [How do I create dynamic variable names inside a loop?](https://stackoverflow.com/questions/8260156/how-do-i-create-dynamic-variable-names-inside-a-loop) – Chirag Ravindra Jun 14 '18 at 09:19
  • @ChiragRavindra the question is about JMeter variables – Ori Marko Jun 14 '18 at 09:23
  • @user7294900 I'm sorry. I might have misunderstood. I was going by this `Is there a way to operate with it within JS or Groovy script loop`. Which asks specifically about JS and the question has been tagged as javascript :) That being said, I still feel the question marked as a possible duplicate (and specifically, the answer marked in my comment) answers the question OP is asking. – Chirag Ravindra Jun 14 '18 at 09:25

2 Answers2

0

In JMeter you should just concatenate i using vars.get:

for (i = 1; i<n; i++)
{
    log.info(vars.get("d" + i) );
}
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
0
1.upto(n,{
    log.info(vars.get('d' + it))
})

Demo:

Groovy Iterate Variables

More information:

Dmitri T
  • 159,985
  • 5
  • 83
  • 133