Skip to Content

Model filter is missing single quotes to the substring parameter

Hi,

Could anyone please help me understanding and resolving the below issue.

I have create the below filter to get suggestions

var value = oEvent.getParameter("suggestValue");

var filters = [];

if (value) {

filters = [ new sap.ui.model.Filter([

new sap.ui.model.Filter("Equipment",sap.ui.model.FilterOperator.Contains,value) ]) ];

}

the above code returns the following request

Equipment%20asc&$filter=(substringof(701744000,Equipment)) ... here i am missing the single quotes

But this will work if I explicitly pass single quotes in the above code like this

new sap.ui.model.Filter("Equipment",sap.ui.model.FilterOperator.Contains,"'"+value+"'") ]) ];

}

returns the below request

Equipment%20asc&$filter=(substringof(%27701744000%27,Equipment))

Now here is my total confusion with sap.ui.model.Filter...

there is a situation where model filter worked for me without passing explicit single quotes

the code looks like below

var sQuery = oEvent.getParameter("query");

new Filter("EquipmentNumber", FilterOperator.Contains, sQuery);

the request looks like below

EquipmentSet?$skip=0&$top=5&$orderby=EquipmentNumber%20asc&$filter=substringof(%27701744000%27,EquipmentNumber)

Could anyone please help me in understanding it.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Nov 09, 2017 at 03:18 PM

    value=""+value;

    how about doing that before passing to the filter?

    Add comment
    10|10000 characters needed characters exceeded

    • Thanks for the response.

      But why do we need to pass it before and how it makes the difference.

      As i mentioned this code even works without passing single quotes

      var sQuery = oEvent.getParameter("query");

      new Filter("EquipmentNumber", FilterOperator.Contains, sQuery);

      And one more strange thing today the below code works even without passing single quotes but not on the day i posted the question but please let me know in understanding the difference

      new sap.ui.model.Filter("Equipment",sap.ui.model.FilterOperator.Contains,value) ]) ];