Skip to Content

UI5 multiple filter parameters with AND operator with v2.odata model

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();							}
	        });
Add comment
10|10000 characters needed characters exceeded

  • I am expecting an AND operator so all the parameters passed from UI should be considered by ODATA, but a OR operator between the condition is miss leading query, with V2.Odata filter values must be passed via filters parameter in Odata call

    Thanks

    Rajesh

  • Follow
  • Get RSS Feed

2 Answers

  • Jan 09 at 11:23 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • Rajesh i was wondering logically it should be OR not AND. You want to fetch data kind of for attribute and char value, with AND you will can logically have one combination, OR is correct. What is the output you are expecting from Odata filter cal?

      Nabheet

  • Jan 09 at 01:11 PM

    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

    Add comment
    10|10000 characters needed characters exceeded