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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -