2

My below code is not working for filtering values based on user name

 function onGetUserNameSuccess() {
    var username = user.get_title();
    alert(username);
    var executor;

    executor = new SP.RequestExecutor(appweburl);
    executor.executeAsync({
        url: appweburl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('LateLogin')/items?$select=Author/Title&$expand=Author&$filter=Author/Title eq '"+username+"'?@target='" + hostweburl + "'",

        method: "GET",
        headers: {
            "Accept": "application/json; odata=verbose"
        },
        success: getListItemsSuccessHandler,
        error: getListItemsErrorHandler
    });
}

But it goes to error function.

1 Answer 1

5
/_api/SP.AppContextSite(@target)/web/lists/getbytitle('LateLogin')/items?$select=Author/Title&$expand=Author&$filter=Author/Title eq '"+username+"'?@target='" + hostweburl + "'"

You are passing user's login name in ther but filtering by Title. So modify your url and try

/_api/SP.AppContextSite(@target)/web/lists/getbytitle('LateLogin')/items?$select=Author/Title&$expand=Author&$filter=Author/Name eq '"+username+"'&@target='" + hostweburl + "'"

Author/Title eq "some value" means you are filtering by user's display name

Author/Name eq "some value" means you are filtering by user's login name

And it should be & instead of ? before target.

Main part of the query URL must be ended up by ?. Then other parts will be joined by &

5
  • in browser m getting data with title but not with Name..also pls tell me if there is any error with the syntax.thanks.. Commented Oct 20, 2015 at 9:03
  • username means login name or display name Commented Oct 20, 2015 at 9:06
  • display name... /_api/SP.AppContextSite(@target)/web/lists/getbytitle('LateLogin')/items?$select=Author/Title&$expand=Author&$filter=Author/Name eq 'Vikash Kumar'?@target='" + hostweburl + "'" this also doesnt work Commented Oct 20, 2015 at 9:08
  • in browser it works but in code it does not..\ Commented Oct 20, 2015 at 9:09
  • it should be & instead of ? before target. Commented Oct 20, 2015 at 9:18

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.