Reputation: 365
I want to run a filter 2 times for 2 different values. The below filter runs fine and searches if the material M exists in the plant A. What I want to search is material M exists in Plant A and Plant B. So I want to run the below filter 2 times for Plant A search if the material is present then run for plant B. If both the places it exists then call the success function. Whats the best way to do it? (Plant is like the key)
Controller.js
var sServiceURL = self.getOwnerComponent().getMetadata().getManifestEntry("sap.app").dataSources["ABC"].uri;
var OdataModel = new sap.ui.model.odata.v2.ODataModel(sServiceURL);
var sPath = "/materialSet";
var filters = [];
filters.push(new sap.ui.model.Filter([
new sap.ui.model.Filter("plant", sap.ui.model.FilterOperator.EQ, self.plantA),
new sap.ui.model.Filter("plant", sap.ui.model.FilterOperator.EQ, self.plantB)
], true));
filters.push(new sap.ui.model.Filter("Material", sap.ui.model.FilterOperator.EQ, materialNo));
filters.push(new sap.ui.model.Filter("type", sap.ui.model.FilterOperator.EQ, orderType));
OdataModel.read(sPath, {
filters: filters,
success: self.sucess.bind(self),
error: function(oError) {
self.error(oError);
}
});
Upvotes: 3
Views: 9407
Reputation: 7250
You can add multiple filters on the same field in this manner:
new Filter([
new sap.ui.model.Filter("plant", sap.ui.model.FilterOperator.EQ, self.plantA),
new sap.ui.model.Filter("plant", sap.ui.model.FilterOperator.EQ, self.plantB)
], false);
This results in a call like:
and ( plant = 1 or plant = 2 )
If your intention is to check if a part is available in both plants, turn it the last parameter into a true
or leave it blank:
new Filter([
new sap.ui.model.Filter("plant", sap.ui.model.FilterOperator.EQ, self.plantA),
new sap.ui.model.Filter("plant", sap.ui.model.FilterOperator.EQ, self.plantB)
], true);
and (plant = 1 and plant = 2)
So, incorporate this as a replacement for filters.push(new sap.ui.model.Filter("plant", sap.ui.model.FilterOperator.EQ, self.plant));
.
Upvotes: 4