Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How to apply multiple filter in oData.read()

Hi Friends,

I need help in filter in to read oData. I need filter as following while performing oModel.read().

(

((USERID EQ 'KSA') OR (USERID EQ 'KSW'))

AND

((USERID NE 'KUMARNISH2') OR (USERID NE 'KUMARNISH3'))

)

If you see here there are multiple OR operation and atlast all are AND with each other.

I has following code:

var filters = [];

  // var filters_ne = [];

  var filter;

  for (var i in employee){

  var token = employee[i].getText();

  if(token.startsWith("=")){

  //equal to

  filter = new sap.ui.model.Filter("UserID", "EQ",token.substring(1));

  filters.push(filter);

  }else if(token.startsWith("!")){

  //not equal to

  var notUser = token.substring(3);

  notUser = notUser.substring(0,notUser.length-1);

  filter = new sap.ui.model.Filter("UserID", "NE",notUser);

  filters.push(filter);

  }else{

  //between

  var userid = token.split("...");

  filter = new sap.ui.model.Filter("UserID", "BT",userid[0],userid[1]);

  filters.push(filter);

  }

  }

  // filters.push(filters_ne);

  // var allFilter = [];

  // allFilter.push(filters_eq);

  // allFilter.push(filters_ne);

  // var filters = new sap.ui.model.Filter(allFilter, true);

  this.getView().getModel().read("/I_Userdetails",{

  filters :filters,

  success : jQuery.proxy(this.updateUserData,this),

  error : this.failed

  });

Tags:
Former Member
Not what you were looking for? View more on this topic or Ask a question