4

I have a custom list with 37 user fields, I need to check if the current user is in one of those fields to display an alert.

I'm getting the current user with this url:

/_api/web/currentUser

And then I'm checking the user id against the ids in the custom list by doing 37 filters

/_api/web/lists/getbytitle('Global Contact List')/items?$filter=((field1 eq '"+ userId +"') or (field2 eq '"+ userId +"') ...

But apparently I'm not allowed to make more than 35 filters.

Can someone help me achieve this approach?

Thanks

  • 2
    You need to get whole list item and then check current user in each list item field manually..!! – Kaushal Khamar Dec 30 '15 at 4:49
5

GET request has maximum length limit configured in the web.config. It is 260 characters I guess. So it is the reason you can not make more than 35 filters.

So now you can consider POST and CAML. Make a CAML Query like following. field1 and field2 are considered in the following query. Do not forget to include others.

var query = "<View> " + 
 "  <Query> " + 
 "    <Where> " + 
 "      <Or> " + 
 "        <Eq> " + 
 "          <FieldRef Name=\"field1\" /> " + 
 "          <Value Type=\"Integer\"> " + 
 "            <UserID Type=\"Integer\" /> " + 
 "          </Value> " + 
 "        </Eq> " + 
 "        <Eq> " + 
 "          <FieldRef Name=\"field2\" /> " + 
 "          <Value Type=\"Integer\"> " + 
 "            <UserID Type=\"Integer\" /> " + 
 "          </Value> " + 
 "        </Eq> " + 
 "      </Or> " + 
 "    </Where> " + 
 "  </Query> " + 
 "</View> "

Request Body

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

Now make a POST request to the following URL. I hope it will serve your purpose.

"/_api/web/lists/getbytitle('Global Contact List')/getitems";

Following things may help you to build CAML

  1. U2U Caml Query Builder
  2. Building CAML for querying List in SharePoint
  • 1
    Technically inaccurate, GET has no specified limit, if a server cant handle the length of a request it must respond with 414 URI Too Long – James Love Dec 30 '15 at 23:35

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.