4

I have Date column in list on based it i have create two calculated column month and year.

Now i am trying to get data for particular month and year so I have give filter in REST query but it give Bad request error.

my query like below:

?$select=Type,EmpName/ID,EmpName/Title,Time&$expand=EmpName&$filter=(Month+eq+10)+and+(Year+eq+2016)
  • Any help from my answer? – Atish Dipongkor - MVP Nov 25 '16 at 5:01
  • @AtishDipongkor thanks for replay and answer. but i didn't want to use CAML query. – Vishal Thakkar Nov 25 '16 at 5:06
  • Then $filter on calculated is not possible – Atish Dipongkor - MVP Nov 25 '16 at 5:16
4

$filter does not work with calculated columns. In that case you have to write a CAML query and make a POST request.

Request End-Point

/_api/Web/Lists/getbytitle('List Name')/GetItems  

CAML

var query = "<View>"+
              "<Query>"+
              "<Where>" +
               "<And>"+
                  "<Eq>"+
                   "<FieldRef Name='Month'/><Value Type='Text'>10</Value>"+
                  "</Eq>"+
                  "<Eq>"+
                   "<FieldRef Name='Year'/><Value Type='Text'>2016</Value>"+
                  "</Eq>"+
                "</And>"+
              "</Where>"+  
              "</Query>"+
              "</View>";  

PS: Check the CAML query before using it.

Request Body

var data = {  
    query: {  
        __metadata: {  
            'type': 'SP.CamlQuery'  
        },  
        ViewXml: query 
    }  
};  

Find other limitation of REST API over here.

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.