The following sample searches for one or more task records and returns the specified property values. For this sample, it is assumed there is one or more tasks already existing with a subject String field value equal to subject.
protected TaskRepository taskRepository;
private List<Task> test_readTasksByCriteria() throws Exception {
// Criterion for task searching
StringFieldCriterion fieldCriterion = new StringFieldCriterion();
fieldCriterion.setComparator(StringComparator.EQUALS_ENFORCE_CASE);
LegacySearchFieldPathExpression fieldPathExpression = new LegacySearchFieldPathExpression();
fieldPathExpression.setSearchKeyPath("shortDescription");
fieldCriterion.setFieldPath(fieldPathExpression);
fieldCriterion.getValue().add(subject);
FieldSearchClause searchCriteria = new FieldSearchClause();
searchCriteria.setOperator(LogicOperator.AND);
searchCriteria.getCriteria().add(fieldCriterion);
tasks = taskRepository.readTasksByCriteria(searchCriteria, 100, getPropertiesToRead());
}
private List<String> getPropertiesToRead() {
List<String> props = new List<String>();
//the list of all available properties displays below but to increase efficiency in your searches, you can omit unnecessary properties from your application and those values will not be returned
props.add("shortDescription");
props.add("uniqueKey");
props.add("currentAssignee");
props.add("categories");
props.add("createdOn");
props.add("modifiedBy");
props.add("version");
props.add("modifiedOn");
props.add("contact");
props.add("project");
props.add("activityItem");
props.add("priority");
props.add("workStatus");
props.add("postingStatus");
props.add("dueDate");
props.add("startDate");
props.add("completedDate");
props.add("completedPercent");
props.add("actualHours");
props.add("estimatedHours");
props.add("rateAmount");
props.add("totalAmount");
props.add("note");
return props;
}