Progress will discontinue Telerik Platform on May 10th, 2018. Learn more

Creating Data Items

Creating Data Items

The Backend Services Android SDK allows you to create a data item by instantiating an object and passing it to the Create() or CreateMultiple() methods.

All objects you pass to the methods must be defined according to the Everlive object model.

Single Item

Use the Create() method to create a new content type item. After the items are created, the server returns the newly generated IDs along with the CreatedAt date on the server. The values are automatically set to the objects you passed.

Book testBook = new Book();
book.setTitle("TestTitle");
app.workWith().data(Book.class).create(testBook).executeAsync();

Normally, you don't need to specify the item ID—a GUID will be generated for you. However, if you need to set a specific ID, such as when importing existing data from an external database, you can do that by simply passing it with the request. Your custom ID must meet the following conditions:

  • Must be unique inside the application
  • Must be a string
book.setId("008541a0-b38a-11e5-84b2-b9c8b2734ef4");
book.setTitle("TestTitle");

You can update system fields such as CreatedAt and CreatedBy. However, you can set them only after doing the following:

EverliveAppSettings everliveAppSettings = new EverliveAppSettings();
everliveAppSettings.setAppId(your-app-id);
everliveAppSettings.setSendSystemPropertiesToServer(true);

EverliveApp app = new EverliveApp(everliveAppSettings);
app.setAccessToken(new AccessToken("Masterkey", "your-master-key"));

Book testBook = new Book();
book.setId("008541a0-b38a-11e5-84b2-b9c8b2734ef4");
book.setTitle("TestTitle");
book.setCreatedBy("19baf610-b38a-11e5-a09d-2f9e6ef2405f");
app.workWith().data(Book.class).create(testBook).executeAsync();

Multiple Items

List<Book> books = new ArrayList<Book>();
for (int i = 0; i &lt; 2; i++) {
   Book book = new Book();
   book.setTitle("Test title " + i);
   books.add(book);
}

app.workWith().data(Book.class).create(books).executeAsync();

Telerik Platform verifies fields marked as unique (IsUnique) just before creating each item. It keeps creating items until it reaches a duplicate value, after which it stops executing the request and returns an error. The rest of the items are not processed.

Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved.