##required: catalogid, detail, view, fieldname
##optional: value, foreignkeyid and foreignkeyvalue
#set ($catalogidother = $context.getRequestParameter('catalogid'))
#if($catalogidother)
#set ($catalogid = $catalogidother)
#end
#ifnull ($fieldname)
#set ($fieldname = $context.getRequestParameter('fieldname')) ##lastmodified
#end
#ifnull($view)
#set ($viewid = $context.getRequestParameter('viewid'))
#end
##we need to load up the existing detail object
#ifnull($detail) ##this is new. To reduce complexity we want to just load up the detail all the time
#if(!$searchtype)
#set ( $searchtype = $context.getRequestParameter("searchtype") )
#end
#if( !$searchtype)
searchtype not found!
#end
## #set( $originalsearcher = $searcherManager.getSearcher($catalogid, $searchtype))
#set ($fieldname = $context.getRequestParameter('fieldname')) ##lastmodified
#set( $detail = $originalsearcher.getDetailForView($viewid, $fieldname, $user) )
#end
#set ($fieldname = $detail.id)
#set( $listid = $detail.getListId())
#set( $csslistid = "listdetail_$fieldname")
##set( $originalsearcher = $searcherManager.getSearcher($catalogid, $listid))
#set( $lsearcher = $searcherManager.getSearcher( $detail.getListCatalogId(), $listid ))
##require both
#set ($listfilterid = $detail.get("listfilterid") ) ##local field that we depend on to get the value, get the value
#if( $listfilterid)
#set( $listfilterdetail = $originalsearcher.getDetailForView($viewid, $listfilterid, $user) )
#set ($remotevalue = $context.getRequestParameter('foreignkeyvalue'))
#if(!$remotevalue)
#set( $remotevalue = $data.get($listfilterid) )
#end
#if(!$remotevalue)
#set ($remotevalue = $context.replaceProperty($detail.defaultvalue) ) ##not used much
#end
#if( $remotevalue)
#set($foreignkeyid = $detail.get("foreignkeyid") ) ##remove column that we search on. Use the value here
#if( !$foreignkeyid)
#set($foreignkeyid = $listfilterid)
#end
#set($query = $lsearcher.query().exact($foreignkeyid,$remotevalue).getQuery() )
#end
#else
#set($query = $lsearcher.query().all().getQuery() )
#end
#if($query)
$query.setSortBy($detail.getDefaultSort())
#end
####$lsearcher.addShowOnly($context, $query)
#set ($types = $lsearcher.search($context, $query))
#ifnull ($value)
#set ($value = $context.getRequestParameter('val'))
#end
#ifnull ($value)
#set ($value = $val)
#end
#ifnull ($value)
#ifnull( $insearch )
#set ($value = $context.replaceProperty($detail.defaultvalue) )
#end
#end
#set($searchfield = $detail.getId() )
#if($types)
#else
[[No values found]]
#end
#if( $caneditlists)
#ifnull($finderhome)
#set($finderhome = $apphome)
#end
+ [[New]] $detail
#end