Ask a Question

how do I access value from query in Groovy script

SOLVED
bgoh29
New Contributor

how do I access value from query in Groovy script

How do I get value from the query in the Groovy script? 

 

I can get the values from the Response by using for example:

 

def driverId = context.expand('${userInfo#Response#$id}')

 

 

However, if I want to get the value of the query parameter to-date, in this example, what do I put in ${ }

bgoh29_0-1642475662777.png

 

3 REPLIES 3
ChrisAdams
Community Leader

Hi,

 

Your question is not completely clear.

 

My take is that you want to 'pull' a value from the Groovy script step and put that value into the 'to-date' parameter for the service call.

 

The syntax for getting the result from a Groovy script step is.... ${Name of Groovy Script step#result}.  The '#result' bit is important, it tells SoapUI to get the returned result from the script.  Also ensure your Groovy script has a return statement at the end.  E.g.

 

 

def someValueToReturn = '17-JAN-2022';

return someValueToReturn;

 

KarelHusa
Regular Contributor

I would recommend to place the value (2022-02-01) into a TestCase property or some other variable which you can easilly access.

Then you can:

  • use its value inside REST Request as e.g. ${#TestCase#toDate}
  • inside Groovy script as well (via context expansion or TestCase Java methods)

Using SoapUI Java API from Groovy to reach the query parameter would be also an option, but probably harder to use and maintain.

 

Best regards,

Karel

 

 Thank you, KarelHusa, 

 

I tried the #testcase#todate solution, didn't quite work for me. However, I discovered a custom properties tab where I can access the values I was looking for without adding too much work for myself.   My Groovy script will use the line of code context.expand to access those values using  #testStep#propertyname. Thank you for pointing me in the direction of looking for information.  

bgoh29_0-1642542704767.png

 

cancel
Showing results for 
Search instead for 
Did you mean: