Ben22
7 years agoSenior Member
Get REST request query parameter in Groovy script
I'm trying to access a query parameter in a REST 'pageNumber' in a Event groovy script. The parameter value is coming from a datasource as you can see in below image.
In my script I can access the query paramter in several ways, but it always gives me the variable name : ${DataSource#pageNumber}.
I don't need the variable name but the actual value that is being sent by the request. Here's what I tried:
def try1 = httpRequest.getProperty("pageNumber").getValue() log.info "try1: " + try1
def try2 = context.getProperty("pageNumber") log.info "try2: " + try2
Result:
Fri Aug 31 12:15:44 CEST 2018: INFO: try1: ${DataSource#pageNumber} Fri Aug 31 12:15:44 CEST 2018: INFO: try2: ${DataSource#pageNumber}
What does work is the following:
def try3 = context.expand( try2 )
Is this the only way to access query parameters or are there other (better) ways. What if the the value comes from somewhere else, like a project property?