Java ServiceAPI and additional fields
Previous posts have described the Java client and file upload. This post details how to fetch the value of additional fields.
Field Names
As described elsewhere the name to use to fetch an additional field is its search clause name, as seen in the client.
Get field values as text
Once you know the correct names for your fields you need to fetch them. A full sample is provided in the samples repo, in short you need to:
- request the fields by name
- request string values be returned
- parse the string value as necessary.
Example
See the samples repo for the full sample.
Records request = new Records(); request.q = "number:rec_222"; // tell the search request to return both string and actual values for the fields and properties request.setPropertyValue(PropertyType.Both); request.setStringDisplayType(StringDisplayType.WebService); request.Properties = makePropertyList("RoadSurface", "DateOfIssue", "PoliceOfficer"); RecordsResponse response = client.get(request); Record rec = response.Results.get(0); ITrimProperty dateOfIssue = rec.Fields.get("DateOfIssue"); SimpleDateFormat parser = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss zzz"); Date date = parser.parse(dateOfIssue.getStringValue()); System.out.println(date);
Written on January 16, 2018