0

i want to filter a list by one spesific column. For exmple i want to see only when [City] = NYC. I tried something likr this:

_api/Lists/getbytitle('EmployeeInfo')/items?$filter=City eq NYC

But it's doesn't work for me.

thank

EDIT:

1.  $.ajax({  
2.    
3.          url: "/_api/web/lists/getbytitle('employeeInfo’)/items?$filter=City eq 'NYC'",
4.          headers: { Accept: "application/json;odata=verbose" },  
5.          method: GET,
6.          success: function (data) {  
7.                 Console.log("success");
8.              }    
9.          },error: function (data) {  
10.         alert("An error occurred. Please try again.");  
11. }  
12.     });  
13. }  
  • 1
    here the issue is in the single quote replace 'employeeInfo’ with 'employeeInfo' – SynozeN Technologies May 17 '17 at 12:07
1

Please try below code:

$.ajax({      
          url:  webUrl + "/_api/web/lists/getbytitle('employeeInfo’)/items?$filter=City eq 'NYC'",
          headers: { Accept: "application/json;odata=verbose" },  
          method: GET,
          success: function (data) {  

                 alert("success");
              }    
          },error: function (data) {  
                alert("error");  
            }  
     });  
 }   

Hope it works for you.

  • hey thanks. i changed it, but still not working. i try to run it via WebPart/Javascript. – uRIELk May 17 '17 at 11:45
  • can you please give whole ajax call whichever used in your code? – Samir Khimani May 17 '17 at 11:47
  • please check updated answer – Samir Khimani May 17 '17 at 12:19
0

Please try below :

_api/Lists/getbytitle('EmployeeInfo')/items?$filter=City eq 'NYC'
0

You are missing the text web in the endpoint.

Also ensure the City column is the internal name and not display name.

$filter works on the internal name of the column

Try it as below:

/_api/web/Lists/getbytitle('EmployeeInfo')/items?$filter=City eq 'NYC'

Your code would be as below:

var webUrl = _spPageContextInfo.webAbsoluteUrl;
//webUrl = url of the site where list is available
//var webUrl = "https://sitecollectionurl/subsite";  

$.ajax({      
          url:  webUrl + "/_api/web/lists/getbytitle('employeeInfo')/items?$filter=City eq 'NYC'",
          headers: { Accept: "application/json;odata=verbose" },  
          method: GET,
          success: function (data) {  
                 console.log(data);                  
                 console.log("success");
              }    
          },error: function (data) {  
                console.log("An error occurred. Please try again.");  
            }  
     });  
 }  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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