Home Ask Login Register

Developers Planet

Your answer is one click away!

Veena February 2016

How to pass variable holding a value to groovy eq query?

How can I pass variable holding a value instead of passing a value directly to groovy search criteria?

for (def payee in payees)
    def results = resp.cases.find("eq 'hrid','7547') // hard code values work
    def results = resp.cases.find("eq 'hrid',??????) // how can I pass payee

I'm new to this. Please help. thanks


Michal_Szulc February 2016

Basing on examples, check it:

def results = resp.cases.find { case -> case.hrid == payee }

Emmanuel Rosa February 2016

GORM criteria queries are quite different than your example. Let's say you have a Payee domain class with a property named hrid:


class Payee {
    String hrid

To get a list of all the Payee instances with an hrid of 7547, you'd run a criteria query like this:

String hridValue = '7547'

List payees = Payee.withCriteria {
    eq 'hrid', hridValue

I explain Grails GORM queries in depth in a series of articles starting right here.

Post Status

Asked in February 2016
Viewed 3,471 times
Voted 9
Answered 2 times


Leave an answer

Quote of the day: live life