on 2019 Jan 09 10:08 AM
Hi All,
I want to pass multiple filter parameters with AND operator. for requirement I need to construct my Odata query like below
$filter: EntityType eq 'Duplicate' and Attribute eq 'Name' and CharacteristicValue eq 'Abc' and Attribute eq 'Country' and CharacteristicValue eq 'US'
This is hapening when IU manaully construct the above , but if I want to pass as a filters parameter in Odata call(v2.ODataModel) its constructing in a different way like below
$filter: EntityType eq 'dupchk' and ((Attribute eq 'NameOrg1' and CharacteristicValue eq 'ABCD ') or (Attribute eq 'NameOrg2' and CharacteristicValue eq 'ABCD '))
An OR operator between the filter values( highlighted in BOLD) is miss leading my odata.
Below the implementation.
_oFilter1: function() {
return new sap.ui.model.Filter("EntityType", sap.ui.model.FilterOperator.EQ, "dupchk");
},
_oFilter2: function() {
var oDataModel = this.getView().getModel("dataModel");
var vNameorg1 = oDataModel.getProperty('/NameOrg1');
var oFilter2;
oFilter2 = new sap.ui.model.Filter({
filters: [new sap.ui.model.Filter("Attribute", sap.ui.model.FilterOperator.EQ, "NameOrg1"),
new sap.ui.model.Filter("CharacteristicValue", sap.ui.model.FilterOperator.EQ, vNameorg1)
],
and:true
});
return oFilter2;
},
_oFilter3: function() {
var oDataModel = this.getView().getModel("dataModel");
var vNameorg2 = oDataModel.getProperty('/NameOrg2');
var oFilter3;
oFilter3 = new sap.ui.model.Filter({
filters: [
new sap.ui.model.Filter("Attribute", sap.ui.model.FilterOperator.EQ, "NameOrg2"),
new sap.ui.model.Filter("CharacteristicValue", sap.ui.model.FilterOperator.EQ, vNameorg2)
],
and : true
});
return oFilter3;
},
this.oModelCustomer.read(oModelObjEntity, {
filters: [that._oFilter1(), that._oFilter2(), that._oFilter3()],
and : true,
success: function(data, response) {
sap.ui.core.BusyIndicator.hide();
},
error: function(oError) {
sap.ui.core.BusyIndicator.hide(); }
});
Request clarification before answering.
Hi Vaibhav,
I tried even that way before, which is throwing me "Cannot read property 'sPath' of undefined" and I dont see reason for it.
I am wondering is there any way to pass filter query directly with entityType in v2.oDataModel call ?
this.oModelCustomer.read(oModelObjEntity, {
success: function(data, response) {
sap.ui.core.BusyIndicator.hide();
},
error: function(oError) {
sap.ui.core.BusyIndicator.hide();
}
});
oModelObjEntity = "/dupchkSet?$filter=EntityType eq 'dupchk' and Attribute eq 'NameOrg1' and CharacteristicValue eq 'ABCD'"But I can't do with v2.odata, if at least I can pass my filter query like that would slove my issues
Thanks
Rajesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rajesh,
Create your filter like this before passing to the read request :
var aFinalFilter = new sap.ui.model.Filter({ filters: [that._oFilter1(), that._oFilter2(), that._oFilter3()],
and:true
});And then pass the aFinalFilter to read
this.oModelCustomer.read(oModelObjEntity,{filters:aFinalFilter ,
success:function(data, response){sap.ui.core.BusyIndicator.hide();},
error:function(oError){sap.ui.core.BusyIndicator.hide();}});Thanks,
Vaibhav
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi Vaibhav, I have written code somewhat similar to your suggestion. I can see that Odata is now getting called when I put external debugger called however I dont see filter parameters in my DPC ext class method.
Please advise what am I missing here.
// Get Date Range from Selection Screen
handleChange: function (oEvent) {
var sValue = oEvent.getParameter("value");
var filter2 = new sap.ui.model.Filter({
path: "/EntitySet",
operator: sap.ui.model.FilterOperator.EQ,
value1: sValue
});
this.getView().getModel().read("/EntitySet", {
filters: [filter2],
success: function (oData) {},
error: function (oError) {}
});
debugger;
}
| User | Count |
|---|---|
| 14 | |
| 8 | |
| 6 | |
| 6 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.