-2

I'm trying to use the createCriteria in a grails application to return some rows from a DB. I'm not getting any results.

def query = {
    ilike('fullName','%${params.term}%')
    projections {
        property('id')
        property('fullName')
    }   
}

def plist = Patient.createCriteria().list(query) 
def patientSelectList = []
plist.each {
    def pMap = [:] 
    pMap.put("id", it[0])
    pMap.put("label", it[1])
    pMap.put("value", it[1])
    patientSelectList.add(pMap) 
}

the fields i'm looking for exist as the following snippet returns results but is very slow.

def patientList = Patient.getAll()
def patientSelectList = []
patientList.each { patient ->
    if (patient.fullName.toLowerCase().contains(params.term.toLowerCase()) ) {
        def pMap = [:]
        pMap.put("id", patient.id)
        pMap.put("label", patient.fullName)
        patientSelectList.add(pMap)
    }
 }
return patientSelectList

thanks for anyhelp

I had my Db fields encryted with jasypt. Removing the encryption on the field I needed to query fixed the issue!

1 Answers1

0

You're using a String rather than a GString in the ilike() parameter, so params.term is not being evaluated. To use a GString, use double-quotes instead.

ilike('fullName',"%${params.term}%")

Also make sure % is an appropriate wildcard character for your database (it probably is).

Emmanuel Rosa
  • 9,697
  • 2
  • 14
  • 20