Abhi Abhi - 6 months ago 38
Android Question

dreamfactory : Querying records with multiple filters

I am working on an ecommerce android app. I am trying to fetch records using dreamfactory API for android, based on multiple filters.

Using an AsyncTask named as GetProductsBySubCatIdTask

public class GetProductsBySubCatIdTask extends BaseAsyncRequest {

Context context;
public Products productsRec;
int subCatId;
String sort_str,fltr_str;

public GetProductsBySubCatIdTask(Context context, int subCataId, String sort_str, String fltr_str){
this.context = context;
this.subCatId = subCataId;
this.sort_str = sort_str;
this.fltr_str = fltr_str;

protected void doSetup() throws ApiException, JSONException {
callerName = "getProductsBySubCatId";

serviceName = AppConstants.DB_SVC;
endPoint = "product";
verb = "GET";

// filter to only select the contacts in this group

fltr_str = "&&" + fltr_str;
fltr_str = "";

queryParams = new HashMap<>();
queryParams.put("filter", "sub_category_id=" + subCatId + fltr_str);
queryParams.put("order", sort_str);

applicationApiKey = AppConstants.API_KEY;
sessionToken = PrefUtil.getString(context, AppConstants.SESSION_TOKEN);


protected void processResponse(String response) throws ApiException, JSONException {
//Log.d("Tang Ho"," >>>>> " + response);
productsRec =
(Products) ApiInvoker.deserialize(response, "", Products.class);

protected void onCompletion(boolean success) {
if(success && productsRec != null && productsRec.products.size() > 0){
Log.d("Tang Ho"," >>>>> Success");

I have used filters which is constructed outside the class and provided as parameter, the possible filters are

unit_offerprice < unit_mrp<br>
unit_offerprice = unit_mrp<br>
(unit_offerprice > 200) && (unit_offerprice > 500)<br>
unit_offerprice > 100<br>
unit_offerprice < 600<br>

All the above filters can be used either individually or in combination of 2 or 3 like

unit_offerprice < unit_mrp && unit_offerprice > 100

After escaping the symbols in the string like


Not able to get desired result,
Searched in documentations but din't found exact thing.

what can be the possible solution for this ?


If your filter has multiple conditions, each condition needs to be placed inside parentheses (). Additionally, the proper syntax for joining filters with and is AND, not &&. Supported logical operators are AND, OR, and NOT.

In your example, this:

unit_offerprice < unit_mrp && unit_offerprice > 100

should be this:

(unit_offerprice < unit_mrp) AND (unit_offerprice > 100)

See these portions of the documentation: http://wiki.dreamfactory.com/DreamFactory/Features/Database/Records#Filtering_Records http://wiki.dreamfactory.com/DreamFactory/Tutorials/Querying_records_with_logical_filters

DreamFactory also offers a number of official support avenues, including user forums. http://www.dreamfactory.com/support