Search code examples
javascriptnode.jsazureodataazure-mobile-services

How to use substringof in azure-mobile-apps-js-client


I want to make use of odata substringof method using azure-mobile-apps-js-client. Currently I use indexof method but want to switch to substringof.

I have this code

function queryFunction(term){
     return this.FullName.indexOf(term) != -1
}
table.where(queryFunction, term)

Which translates to

$filter=indexof(FullName, term) ne -1

I need URL like this:

filter=substringof(term, FullName) eq true

How do I do that with javascript ?


Solution

  • azure-query-js supports a limited set of Javascript functions that are translated to their odata equivalents. Currently, there is no function that can be mapped to substringof. Your original implementation using indexOf is your best bet for querying for substrings using Javascript style querying.

    However, if you wish to take complete control of querying yourself, you can directly pass an OData query string to the read method. https://github.com/Azure/azure-mobile-apps-js-client/blob/2b5e083d400a089cb1759d6d58d96e4d10ba2310/sdk/test/tests/shared/mobileServiceTables.js#L98 is an example. If you search for '$filter' in the file you will find a few more examples.