I have a search form which has a dropdown list of primary keys to a related entity.
With the following code, if I select a dropdown value, all is good. If I don’t, the call fails as local.objCourseType is NULL
public any function getSearchResults(searchCriteria) {
if (arguments.searchCriteria.type == “”) {
arguments.searchCriteria.type = “not supplied”;
}
local.objCourseType = entityNew(“CourseType”).get(arguments.searchCriteria.type);
local.objCriteria = newCriteria();
local.result = local.objCriteria.iLike(“code”, arguments.searchCriteria.code & “%”)
.and(
local.objCriteria.restrictions.iLike(‘fullTitle’, arguments.searchCriteria.fullTitle & “%”)
,local.objCriteria.restrictions.eq(‘type’, local.objCourseType)
,local.objCriteria.restrictions.eq(‘offerStatus’, arguments.searchCriteria.offerStatus)
)
.list(sortOrder=“fullTitle”);
return local.result;
}
How can I conditionally search for my CourseType?
Richard