Search code examples
jmeter

How to pass or set null value in variable to post request


I'm posting HTTP request and JSR223 pre-processer to pass values like shown below, Steps:

  1. HTTP post request reading values from JSR223 pre-proccesser
  2. Want to send null value for variable

JSR223 pre-processer : vars.put("aptstatus","A") vars.put("isccode",null) I have used above way to pass value but in post request it is shown as

"status": "${aptstatus}", "serviceCode": "${isccode}",

My requirement is to send null value in http post request.

Please help here how to set null value in variable.

Note: serviceCode is VARCHAR type


Solution

    1. In the JSR223 PreProcessor:

      vars.put("isccode", 'null')
      
    2. In the HTTP Request sampler:

      "status": "${aptstatus}", "serviceCode": ${isccode}
      

    You will get:

    "status": "A", "serviceCode": null
    

    Demo:

    enter image description here

    More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?