gorm - How to use findAll in Grails with "if" statement to verify if the field is null before searching -
i need create findall criteria in grails, have 4 fields search. need search fields if specific variable not null.
for example, if variables not null, i'll search fields following:
list = myobject.findall { 'in'("job", joblist) 'in'("businessunit", businessunitlist) 'in'("company", companylist) eq("regulartime", params.regulartime) } what want this:
regulartimelist = regulartime.findall { if(params.job != null) 'in'("job", joblist) if(params.businessunit != null) 'in'("businessunit", businessunitlist) if(params.company != null) 'in'("company", companylist) if(params.regulartime != null) eq("regulartime", params.domainclasssearchfilters.regulartime) } it's not working i'd know if there way because right had create lot of ifs verify them... need 1 if each scenario... like:
if job not null , company not null, 1 findall. if company not null , regulartime not null, findall.
you can this:
regulartimelist = regulartime.findall { if (params.job != null) params.job in joblist if (params.businessunit != null) params.businessunit in businessunitlist if (params.company != null) params.company in companylist if (params.regulartime != null) regulartime == params.domainclass }
Comments
Post a Comment