vlatko606
vlatko606

Reputation: 1149

Jmeter - Using varible: from JDBC request into another JDBC query under loop

For the purpose of my test, Based on the JDBC query id's i need to pass to another query, located under ForEach Controller.

  1. Results return from query1
url id
https://pay1.com/ 1
https://pay3.com/ 3
https://pay8.com/ 8

Based on the ID returned, i need to pass to another query:

select *
FROM transaction  
WHERE id = '${id_1}'

If i try like: ${id_1} or ${id_3} is working fine.

But, how can i pass dynamically to the next query, without hard coding the index?

enter image description here

Upvotes: 1

Views: 356

Answers (1)

Dmitri T
Dmitri T

Reputation: 168072

ForEach Controller has pre-defined variable exposing the current iteration, as per documentation:

JMeter will expose the looping index as a variable named __jm__<Name of your element>__idx. So for example, if your Loop Controller is named FEC, then you can access the looping index through ${__jm__FEC__idx}. Index starts at 0

So

  • given your ForEach Controller name is ForEach Controller you can access its current loop as ${__jm__ForEach Controller__idx}
  • given indices are zero-based and your variables are 1-based you need to add 1 to the current index which can be done using __intSum() function
  • and finally you will need to use __V() function in order to evaluate the resulting expression using your id_ prefix

Putting everything together, the code you're looking for would be something like:

${__V(id_${__intSum(${__jm__ForEach Controller__idx},1,)},)}

Demo:

enter image description here

More information: Here’s What to Do to Combine Multiple JMeter Variables

Upvotes: 2

Related Questions