Forum Discussion

Ben22's avatar
Senior Member
6 years ago

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.


query parameter

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() "try1: " + try1
def try2 = context.getProperty("pageNumber") "try2: " + try2




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?


1 Reply

  • sanj's avatar
    Super Contributor

    Accessing using data source
    def x = context.expand('${DataSource#columnName::0}') #make sure you mention the specific column name and run the whole loop(test case) to see specific values during an iteration. Hope this helps.