My Scenario. [ All are in Same Thread group] I have to Create Cart, Add Multiple Items(5), Update few items(1) and then checkout.

Add Items - I have to add 5 Items [ Each Item will generate unique Item ID] Using For Loop to add 5 times and capture the Item ID value using JSON Extractor. Variable Name= C_Item_ID

JSON Path Expression= $.items[0].id

In JSR223 Postprocessor, i having the below code

def count_value= vars.get("cnt").toInteger(); //convert to int type

For each loop iteration i am capturing the Item ID and store it different variable

switch (count_value) {

     case 1:

       def C_Item_ID_1 = vars.get("C_Item_ID");




Update Item - I need to passing the unique Item ID here.

ex. xxx-service-xxx/cart/1234567890/items/${C_Item_ID_1}

When i reply "${C_Item_ID_1}" value is not getting here.

Not sure what is wrong on this? Any help?

2 Answers 2


After multiple tries the below solution working fine and successfully executed the method and getting correct response.


Thank you all for the support.


Your Groovy code is more or less fine and it should be doing what it is supposed to be doing:

enter image description here

Most probably the issue is with either cnt variable or C_Item_ID variable or both, double check that they have the expected values using Debug Sampler and View Results Tree listener combination. You should see something like:

enter image description here

It also worth checking jmeter.log file for any suspicious entries.

  • Hi Dmitri, thanks for the update. i have double checked in Add Items method all the values are captured and printed. the problem is to get the same value in Update Item method getting "null" value. Ex. 2020-02-03 12:07:05,727 INFO o.a.j.p.j.s.JSR223Sampler: The Counter Value is#1 2020-02-03 12:07:05,727 INFO o.a.j.p.j.s.JSR223Sampler: The Add Item Value is# 9a5b1b4a 2020-02-03 12:07:10,733 INFO o.a.j.p.j.s.JSR223Sampler: The Update Item Value is##### null In Update Method,I am just trying to print the value log.info("The Update Item Value is##### " + vars.get("C_Item_ID_1")); Feb 3, 2020 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.