When you have one field that is directly part of a record, you can construct a criterion with the SearchableField.
Note: If the record does not have direct access to the field but can access it through a field in the record, you must construct a criterion with a FieldPath.
The type of criterion depends on the type of field. The API provides the following criterion types with SearchableField constructors:
•BooleanCriterion—For Boolean fields.
•CategoryCriterion—For categories.
•DateCriterion—For date fields.
•DecimalCriterion—For BigDecimal fields.
•EnumerationCriterion—For enum-based fields.
•FieldCriterion—For all fields.
•IntegerCriterion—For integer fields.
•LookupItemCriterion—For lookup table fields.
•ObjectCriterion—For account, contact, project, and user fields.
•RelativeDateCriterion—For integers before and after a certain date.
•StringCriterion—For string fields.
The SearchableField you use depends on whether the field is a system or custom field.
When you want to search for a system field, use the static field in the model class for the object. You can find a list of static fields for each class in the javadocs: ~\utilities\javadocs\api\index.html
For example, if you are searching on the Location field in appointments, the LOCATION static field is part of the Appointment class. As a result, the SearchableField is Appointment.LOCATION. Before you add the operator, the search field of the criterion looks like the following code.
StringCriterion locationCriterion = new StringCriterion(Appointment.LOCATION) |
When you want to search for custom fields, you can use the CustomField class to retrieve information about fields for a search.
Note: When searching on system fields, use the static system fields in the class for that object. For example, to search with the Location field in appointments, use Appointment.LOCATION.
Use the CustomField class when you have to include custom fields in search criteria. You can use this interface with custom fields of all data types. However, if you are working with projects, Involved parties, or lookup table custom fields, you have the following additional classes:
•ProjectCustomField
•LookupCustomField
•InvolvedCustomField
The following code sample provides an example of how to search using a custom field as the search criteria.
// Get instances of the services we'll need ProjectService projectService = platform.getProjectService(); CategoryService categoryService = platform.getCategoryService();
// Retrieve the custom field CustomField<String> textField = categoryService.getCustomField("fullTreePositionofCategory", "customFieldName");
// Find records with the given custom field set to "Test value" StringCriterion stringCriterion = new StringCriterion(textField).equalTo("Test value"); SearchCriteria searchCriteria = new SearchCriteria(stringCriterion);
// Execute search and return results return projectService.search(“DISP”, searchCriteria”); |