Sample Automation Scripts

Search on Extended Attributes

# Retrieve a folder to search in
#set($folder = $FolderTool.findByPath('/Default/Emails'))

# Retrieve the template by it's name
#set($templateDao = $ContextTool.getBean('TemplateDAO'))
#set($template = $templateDao.findByName('email', $folder.tenantId))

# Prepare the list of search criteria
#set($criteria = [])

# Prepare the condition on the root folder
#set($criterion = $ClassTool.newInstance("enterprise.search.Criterion"))
$criterion.setComposition("and");
$criterion.setLongValue($folder.id);
$criterion.setType(101);
$criterion.setOperator("inorsubfolders");
$criterion.setField("folder");
$criteria.add($criterion);

# Prepare the condition on the extended attribute sendername
#set($criterion = $ClassTool.newInstance("enterprise.search.Criterion"))
$criterion.setComposition("and");
$criterion.setField("sendername");
$criterion.setType(0);
$criterion.setOperator("contains");
$criterion.setStringValue("john");
$criterion.setExtendedAttribute(true);
$criteria.add($criterion);

# Instantiate the search options
#set($options = $ClassTool.newInstance("enterprise.search.ParametricSearchOptions"))
$options.setMaxHits(100);
$options.setUserId(1);
$options.setRetrieveAliases(false);

# Define the template we want to use
$options.setTemplate($template.id);

# Put all the criteria
$options.setCriteria($criteria);

# Get the ParametricSearch object and execute the search
#set($searchFactory = $ClassTool.newInstance("enterprise.search.ParametricSearch"))
#set($search = $searchFactory.get($options))
$log.info("Search $search");

# Search and iterate over the results  
#set($hits = $search.search())
#foreach($hit in $hits)
  $log.info("Hit: $hit.fileName");
#end

This procedure searches for all those documents within the /Default/Emails folder that are emails and the sendername attribute contains john.