6

I would like to bind all users into textbox autocomplete event. I done with below script but it is consider case sensitive expression while searching the results.

  $("#txtselectuser").autocomplete({
    source: function (request, response) {

        jQuery.ajax({
            url: appwebUrl + "/_api/web/SiteUsers?$filter=startswith(Title,'" + request.term + "')",
            method: "GET",
            async: true,
            headers: {
                "accept": "application/json;odata=verbose",
                "content-type": "application/json;odata=verbose",
                "X-RequestDigest": $("#__REQUESTDIGEST").val()
            },
            success: function (data) {
                var results = data.d.results;
                response($.map(results, function (item) {
                    return {
                        label: item.Title,
                        val: item.Id
                    }
                }))
            },
            error: function (data) {
            }
        });
    },
    select: function (e, i) {
        $("#txtselectuser").val(i.item.label);
        $("input#elm_inputuserid").val(i.item.val);

    },
    minLength: 1
});

It will returns results based on Display Title of all users. For Example : We have couple of users 1) Jignesh Rajput 2) Jigs

When I searched on Textbox with Jig - it will return both of users but I have type on textbox with jig(all lowercase characters) it will return 0 results.

Here is link for showing all filter expression for REST API.

I want - will not carry case-sensitive characters and return all matches results.

I tried with tolower functional expression however it is not working.. like :

 ?$filter=startswith(tolower(Title),'jig')",
1
  • How many users do you expect? Workaround might be to get all of the users from the list, load the into a JS object with a calculated lower-cased title property, then request further info for them later by their ID -- this only works for a limited number of users though naturally
    – John-M
    Oct 10, 2014 at 14:12

2 Answers 2

10

According to OData query operators supported in the SharePoint REST service tolower operator is not supported.

Solution 1

Use listdata.svc REST endpoint instead.

In your case, the request for finding User by Display Name could be converted into this one:

/_vti_bin/listdata.svc/UserInformationList?$filter=startswith(Name,'<Name>')  

Key Points:

  • User Information List is used for query the User
  • tolower operator is omitted since the specified request is case-insensitive

Solution 2

The idea is to apply some kind of verification for the value passed into filter query option, for example:

function capitalize(name)
{
    return name[0].toUpperCase() + name.slice(1);
}

Source

var endpointUri = appwebUrl + "/_api/web/SiteUsers?$filter=startswith(Title,'" + capitalize(request.term) + "')";
0
4

Unfortunately, tolower is not supported by the SharePoint 2013 REST API

screenshot from MSDN documentation

From the SharePoint 2013 REST Service article on MSDN

This is one of those areas where SharePoint still differs from the standard web-world implementation :)

0

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.