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.

adf.PNG

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:

  1. request the fields by name
  2. request string values be returned
  3. 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);

Java ServiceAPI client

Prior to Content Manager 9.0 there was no supported Java client for the ServiceAPI, although I did publish an experimental project.  As of 9.0 we are able to use the ServiceStack Java client.  This video demonstrates that client. 

The code

The sample project I created in the video is on our samples site. Beware, in the video I omit the call to 'setAlwaysSendBasicAuthHeaders', you should always call this when using basic authentication.