title: How to return dynamic response in SoapUI MockService
body: <p>I am new to SoapUI and have just configured a very simple MockService. Is it possible to manipulate the response so that for a particular request the response's elements are dynamically built up?</p>
  
  <p><strong>Scenario 1:</strong></p>
  
  <p>Request:</p>
  
  <pre><code>&lt;record&gt;
    &lt;identifier&gt;ID1&lt;/identifier&gt;
  &lt;/record&gt;
  </code></pre>
  
  <p>Response:</p>
  
  <pre><code>&lt;response&gt;
    &lt;child1&gt;child 1&lt;/child1&gt;
  &lt;/response&gt;
  </code></pre>
  
  <p><strong>Scenario 2:</strong></p>
  
  <p>Request:</p>
  
  <pre><code>&lt;record&gt;
    &lt;identifier&gt;ID2&lt;/identifier&gt;
  &lt;/record&gt;
  </code></pre>
  
  <p>Response:</p>
  
  <pre><code>&lt;response&gt;
    &lt;child2&gt;child 2&lt;/child2&gt;
  &lt;/response&gt;
  </code></pre>
  
  <p>It is for a simple test and I don't need it to do any more than the above. I am currently doing the following that yields the results I want but since I am completely new to this I am sure there are better alternatives:</p>
  
  <p>Response:</p>
  
  <pre><code>&lt;response&gt;
    ${dynElement}
  &lt;/response&gt;
  </code></pre>
  
  <p>Groovy script:</p>
  
  <pre><code>def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
  def holder = groovyUtils.getXmlHolder(mockRequest.requestContent)
  def reqRef = String.valueOf(holder.getNodeValue("//identifier"))
  
  def child1Text = "&lt;child1&gt;child 1&lt;/child1&gt;"
  def child2Text = "&lt;child2&gt;child 2&lt;/child2&gt;"
  
  if (reqRef == "ID1") {
    context.setProperty("dynElement", child1Text)
  } else if (reqRef == "ID2") {
    context.setProperty("dynElement", child2Text)
  }
  </code></pre>