Getting a Subset of Fields

Getting a Subset of Fields

When you read data from Telerik Platform, you can choose to receive only a subset of all available fields for each item. This saves bandwidth and can improve your app performance because data is fetched from the server faster. By default, all fields are returned from the server.

Specifics

The Id field is always returned by the server. In order to omit it you need to exclude it explicitly from the projection.

You cannot use inclusion and exclusion definitions simultaneously besides the case when you are including fields and excluding the Id field.

Including Fields

To project only a subset of fields to the result, you need to add the included fields to a FieldsDefinition and pass it as an argument to the select method.

The following method will return only the specified fields:

public ArrayList<Book> GetBooks(EverliveApp app) {
    FieldsDefinition includedFieldsDefinition = new FieldsDefinition();
    includedFieldsDefinition.addIncludedFields("Author", "Title");
    
    RequestResult<ArrayList<Book>> requestResult = app.workWith().data(Book.class).get().
    select(includedFieldsDefinition).executeSync();
    return requestResult.getSuccess() ? requestResult.getValue() : null;
}

Excluding Fields

Alternatively, you can specify which fields to exclude, by adding the excluded fields to a FieldsDefinition to and passing it as an argument to the select method.

The following method will return all, but the specified fields.

public ArrayList<Book> GetBooks(EverliveApp app) {
    FieldsDefinition excludedFieldsDefinition = new FieldsDefinition();
    excludedFieldsDefinition.addExcludedFields("ModifiedAt");
    
    RequestResult<ArrayList<Book>> requestResult = app.workWith().data(Book.class).get()
    .select(excludedFieldsDefinition).executeSync();
    return requestResult.getSuccess() ? requestResult.getValue() : null;
}

Including Fields and Excluding the Id

The following snippet is the only case when the simultaneous usage is allowed:

public ArrayList<Book> GetBooks(EverliveApp app) {
    FieldsDefinition fieldsDefinition = new FieldsDefinition();
    fieldsDefinition.addIncludedFields("Author", "Title");
    fieldsDefinition.addExcludedFields("Id");

    RequestResult<ArrayList<Book>> requestResult = app.workWith().data(Book.class).get()
    .select(fieldsDefinition).executeSync();
    return requestResult.getSuccess() ? requestResult.getValue() : null;
}
Start a free trial Request a demo
Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved.