3

How can I filter multiple columns in REST API using Name/Username when running GET request to UserInformationList?

Here is my Query:

 var getPeoplePickerSuggestion = function(searchKey) {
        var userSearchSuggestionEndpoint = "/_vti_bin/ListData.svc/UserInformationList?$select=Id,Name,UserName,WorkEmail&$filter=substringof('" + searchKey + "',Name)";
        return baseSvc.getRequest(userSearchSuggestionEndpoint);
    }
3
  • What are all the columns you want to apply filters? Commented Jun 24, 2016 at 12:46
  • 1
    Have you tried adding another condition? Should be able to simply do "$filter=substringof('" + value1 + "', Key1) and substringof('" + value2 + "', Key2)"
    – wjervis
    Commented Jun 24, 2016 at 12:47
  • You need to know how filter works. codeproject.com/Articles/990131/… Commented Jun 24, 2016 at 12:48

2 Answers 2

3

Please see the below example, you can use the "and" operator, to meet multiple conditions,

  http://{server_name}/_vti_bin/listdata.svc/UserInformationList?$filter=((ContentType eq 'Person') 
  and (substringof(Name,'{query}')))&$orderby=Name

Also, shared by Atish, on the following page, it shows you multiple other operators, you can use in your filter, such as,

You may notice that I have used a query operator like ‘eq’ in above URL. Now let’s see what are the other query operators available, for strings, numeric, and datetimes.

enter image description here

1
  • Keep in mind you need to escape ' like: substringof(Name,'Bob's Burger') -> substringof(Name,'Bob''s Burger') Commented Jun 24, 2016 at 14:48
0

i ended up with query below, works fine for me now, and i can search on LoginName, Title, or Email.

`var userSearchSuggestionEndpoint = "/_api/web/SiteUsers?$filter=(substringof('" + searchKey + "',LoginName) or substringof('" + searchKey + "',Title) or substringof('" + searchKey + "',Email))";
        return baseSvc.getRequest(userSearchSuggestionEndpoint);`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.