Android SDK: Problem with createRecord API

I was trying to create a simple record using android client SDK and had problems.
The schema is pretty simple:
Name Type
FAVOR boolean
ID id
record_id integer
USER_ID user_id_on_create
ID is primary key. I was trying to use the follow API but do not know how to prepare a good
recordRequest.
RecordResponse result = dbApi.createRecord(IAppConstants.FAVOR, recordRequest.getId(), recordRequest, null, null, null, null);

The record does created, but only with auto increase id and user_id. Fields of record_id and favor are not able to be persisted.

I did tried to use the live API in dreamfactory and prepared a jason for the body area:
{
“id”: 15,
“favor”: “true”,
“record_id”: 10
}

got error response:
{
“error”: [
{
“context”: null,
“message”: “Create record by identifier not currently supported.”,
“code”: 400
}
]
}

could you give me an example how to persist my model data ? especially about the field in
recordRequest.
Mine
recordRequest.set_field_(Arrays.asList(new String[]{“id”,“1”,“favor”,“true”,“record_id”,String.valueOf(favorItem.getRecord_id())}));

not working.

Thanks for your support.
Tim

Parameters in createRecord functions are wrong or i should say it is working as expected because you are passing id only to create record.

Please have a look to sample to-do app class name is ToDoDemoActivity.java. and check CreateRecordTask. You have to create a model class similar to RecordRequest (you can modify same class with your fields) and then pass RecordRequest object. Also check readme file @ https://github.com/dreamfactorysoftware/android-sdk

RecordRequest record = new RecordRequest();
record.setName(“some text”);
DbApi dbApi = new DbApi();
dbApi.addHeader(“X-DreamFactory-Application-Name”, “your app name”);
dbApi.setBasePath(“your DSP url”);
dbApi.addHeader(“X-DreamFactory-Session-Token”, “your session id”);
RecordResponse resultRecord = dbApi.createRecord(“table name”, “123”, record, null, null, null, null);

Let me know if this helps.

Thanks,
at

Hi Alokt,

Thanks for your reply. Your answer help me with confidence to extend the RecordRequest and partially persisted one more field.

I did look at the toDoDemoActivity and was confused about the model usage since I found the TodoItem Model is not used in the whole code at all. The passed in parameter is not the ToDoItem model but a string parameter, which made me wonder why TodoItem is not used at all.

protected RecordResponse doInBackground(String… params) {
String todoItem = params[0];

I seemed to me that the only way to pass data to server is through RecordRequest.
However, since RecordRequest is the SDK model, I dare not to change it.
I carefully looked into RecordRequest and found fields as key-value, looking like the only way to pass data to server. That is why you saw my attempts with:

recordRequest.set_field_(Arrays.asList(new String{“id”,“1”,“favor”,“true”,“record_id”,String.valueOf(favorItem.getRecord_id())}));
Never worked. But that is my thought process, hopefully it is a reference for newer to createRecord API.

Following your reply, I moved brave step and extends the RecordRequest and mimic-ed the Jason fields. Good news is record_id has been persisted.
bad news is isFavor not persisted even I set it to true within the background Task.

public class FavorItemModel extends RecordRequest{

@JsonProperty("record_id")
int record_id;
@JsonProperty("user_id")
String user_id;
@JsonProperty("favor")
boolean isFavor ;

So my questiosns are

  1. why boolean is not persisted to server ? would it be better if it is string type?
  2. is the JsonProperty redundant here?

Thanks,
Tim

Reporting progress,

I changed the @JsonProperty(“favor”)
boolean isFavor ; to integer type both client and server side,
it is persisted as well.

String type I guess should work, but have not tried yet.

great it helped, always feel free to extend classes, those model classes are for demo purpose.

boolean should also work, make sure @JsonProperty(“favor”) is same on which it is being used on server side.

Let me know if any other issues.

1 Like