cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Model Filter not taking string(with quotes) value

Former Member
0 Likes
2,186

Hi

After spending several hours to fix this and trying out several possibilities, i still cannot manage to make it work, Here is the issue

Below is the code


var ofilter = new sap.ui.model.Filter({

               path: "Property",

               operator: sap.ui.model.FilterOperator.EQ,

               value1: "Something"

          });

.../EntityName?$filter=Property eq 'Something' - This is how the string SHOULD be formed

.../EntityName?$filter=Property eq Something - This is how it IS formed(notice the missing quotes


I get the below error if if the url is not formed in the "should" way


Invalid filter expression: 'Property eq Something '

Does anyone have any suggestions to fix this?

Thanks

Jayant

View Entire Topic
abaper_guy
Active Participant
0 Likes

Can you try with value1 : "'Something'"

(Double Quote , then single quote then text something followed by single quote then doublequote)

Regards

Amber

Former Member
0 Likes

Hi Amber,

The trick you mentioned works, BUT t i had made the example simple for easy understanding. In the actual case i have a variable instead of "Something" and it again does not treat it as a string. Ex

var ofilter = new sap.ui.model.Filter({

               path: "Property",

               operator: sap.ui.model.FilterOperator.EQ,

               value1: oVar

          });

Do we have any workaround for variables as well?

Thanks

Jayant

Former Member
0 Likes

I have somehow made it work but very unsatisfied with the approach

var oQuote = "'";

var oVar1 = oQuote.concat(oVar, "'");

I am sure either there is a better solution or some issue with the standard behavior w.r.t. filtering.