title: Generating and passing dynamic JSON request body to a POST API request in SoapUI using Groovy Script
body: <p>I am trying to generate dynamic JSON request body for an API automation using SOAP UI. I am using groovy script to do the same. 
  I am not able to pass the dynamically generated property values to my JSON body in the request. Can someone please help?</p>
  
  <p>My Groovy Script</p>
  
  <pre><code>import java.util.Random
  
  //generating random values
  Random rand = new Random()
  String brandName = "BrandName" + rand.nextInt(100000)
  String pageTitle = "BrandPageTitle" + rand.nextInt(100000)
  
  //setting test case properties
  testRunner.testCase.setPropertyValue("name", brandName);
  testRunner.testCase.setPropertyValue("page_title", pageTitle);
  </code></pre>
  
  <p>Here is my JSON Body for the POST Request. I am not sure the way I am accessing the variables in the below JSON is correct</p>
  
  <pre><code>{
    "name": "${brandName}",
    "page_title": "${pageTitle}"
  }
  </code></pre>
  
  <p>I also tried this. 'POSTCreateNewBrand' is my TestCase name and 'name' is the property_name</p>
  
  <pre><code>{
    "name": "${#POSTCreateNewBrand#name}",
    "page_title": "${#POSTCreateNewBrand#page_title}"
  }
  </code></pre>
  
  <p>When I run my tests I see that the name field is not getting supplied as part of the request body and see the below error</p>
  
  <pre><code>&lt;errors&gt;
     &lt;error&gt;
        &lt;status&gt;400&lt;/status&gt;
        &lt;message&gt;The required field 'name' was not supplied.&lt;/message&gt;
     &lt;/error&gt;
  &lt;/errors&gt;
  </code></pre>