How to iterate through with users id in Dataquerybuilder

I want to retrieve let say 10 users by using their ownerId. Setting this in where clause and getting the answer only return just one(the last) user.
NB I hv gotten the users ownerId already. All I need is to get all the users as a response instead of retrieving just one.

Hi @Yomade_Stephens

what API do you use for retrieving these users? and what “whereClause” did you use?

Regards, Vlad

Let say a current user is following ten different users. All I did was to…

// this is a custom class to retrieve the current user
String Id = connection.currentuser.getuserid;

Backendless.data.of.(following.class).find(“ownerid =’”+id+"’",new asy…){

Handle response {

For(i = 0; i<response.size; i++){

String followingid = response.get(i).getownerid
}
}

Handle fault{

}
}

Dataquerybuilder query = new Dataquerybuilder.create;

query.setwhereclause(“ownerId =’”+id+"’ OR ownerId =’"+ followingid +"’");

Backendless.Data.of(Broadcast.class).find(query, new asy… ){
On Handle response {

}

On handle fault {

}
}

The result end up returning the current users broadcast and the last user in the first response broadcast.

I see, in your provided code you load just two users, one where “ownerId=id” and another one with query “ownerId=followingid” inside each iteration.

instead of that, you can build the correct query in the loop and only then load all the necessary users in a single API call

Take a look at the abstract code:

userIds = new Array
for(i = 0; i<response.size; i++){
  userIds.push(response.get(i).getOwnerId)
}

Dataquerybuilder query = new Dataquerybuilder;

query.setwhereclause(“ownerId IN ( userIds.join(,) ));

Backendless.Data.of(Broadcast.class).find(query)

You can find more information about “whereClause” by the following link: https://backendless.com/docs/android/data_search_with_where_clause.html

Also, since there are relations I can recommend you to take a look at this doc https://backendless.com/docs/android/data_relations_retrieve_overview.html
perhaps you are able to load those users with a more elegant way

Regards, Vlad

Thanx for the response but what do u mean by
new Array

Couldn’t get to it in my ide

Try new ArrayList

Tried this it wasn’t returning any response.

could you please provide with us what “whereClause” string has been sent to the server?
Have you tried to test the “whereClause” in the REST Console in Data Section?

OK just like u said in the previous code given.

I made an arraylist first with the idenifier “query”

Arraylistquery = new Arraylist<>();
After this I iterated the response Of The people the current user is following. Let say the response is 5.

Getting the current user Id.
String Id = connection.getuserId;

Setting the where clause in the querybuilder.
Querybuilder.setwhereclause(“Owner_id IN (’”+id+"’, ‘"+query+"’)");
Now setting d query to
Backendless. Data. Of(broadcast).find(query, asy)
But it returns that Of the current user alone and the other query been left empty.

I believe you need to change “Owner_id” to “ownerId”.

please provide how this “whereClause” looks like after all calculation

Even with changing to ownerid it’s still return the same thing. Just that Of the current user. Leaving the array blank

ownerId I mean

please provide how this “whereClause” looks like after all calculation

could you please print the value and share it with us?

Regards, Vlad

Don’t mean to disturb but by value what really do u what or what really would u like me to send back. Wouldn’t want to send the wrong details.

I’m talking about this one

Querybuilder.setwhereclause(“ownerId IN (’”+id+"’, ‘"+query+"’)");

please print this value into log output

Log.d(TAG, “ownerId IN (’”+id+"’, ‘"+query+"’)")

alrit.

ownerId IN (’[8F853961-7DBB-DE4F-FFDC-9F371F5D1200, 56F72132-BAC2-7C93-FFE9-3F28C0BFED00, 6A630BBA-C7E7-54D3-FF97-991201D30B00]’, ‘AEDF902B-CD0C-9214-FF14-99453CAF0500’)

as you can see the value is not corrected, each ObjectId must be wrapped with quotes

ownerId IN ('8F853961-7DBB-DE4F-FFDC-9F371F5D1200', '56F72132-BAC2-7C93-FFE9-3F28C0BFED00', '6A630BBA-C7E7-54D3-FF97-991201D30B00', 'AEDF902B-CD0C-9214-FF14-99453CAF0500’)

am guessing it’s the arraylist.

Cause I did retrieve the people the current user is following using an api call which is correct then iterate them to an arraylist.

Like this
Arraylist array = new Arraylist<>();

//response here is the result of all the user the current user is following.
For(i=0; i<response.size; i++){
Array.add(response.get(i).getuserid);
}

So am I wrong in this aspect?

OK so how do I get my result to return this

do you mean how to compose this string: ownerId IN ('8F853961-7DBB-DE4F-FFDC-9F371F5D1200', '56F72132-BAC2-7C93-FFE9-3F28C0BFED00', '6A630BBA-C7E7-54D3-FF97-991201D30B00', 'AEDF902B-CD0C-9214-FF14-99453CAF0500') ?