1

I am facing issue with Author field. Below query is working on normal list. But it's not working on Survey list. Help me on this issue It is showing error message like "The field 'Author' of type 'User' cannot be used in the query filter expression."

Query is: /_api/Web/Lists/getByTitle('List Title')/items?$select=Id,AuthorId&$filter=(AuthorId eq UserID)

1

It turns out that the Survey list is the special type of list, whose Author field is not the same as in other lists. I got the Author field definition through CSOM, and there are two different attributes in it:

  • Sortable="FALSE"
  • Filterable="FALSE"

The field definition is as follows:

    <Field ID="{1df5e554-ec7e-46a6-901d-d85a3881cb18}" ColName="tp_Author" RowOrdinal="0" 
    ReadOnly="TRUE" Type="User" List="UserInfo" Presence="FALSE" 
    Name="Author" DisplayName="Created By" ForcedDisplay="***" Sortable="FALSE" 
    Filterable="FALSE" AllowMultiVote="FALSE" SourceID="http://schemas.microsoft.com/sharepoint/v3" 
    StaticName="Author" FromBaseType="TRUE" />

The Filterable="FALSE" causes your problem.

  • Is there any way to change Author as filterable? – Saidarao M Feb 21 '17 at 2:15
1

I am fully agreed with Damjan Tomic. Author(Created By) field in survey lists is not filterable.

So you can't use REST with filtering by author. But you can use CSOM or SPServices library

For example, code below checks is current user answered to survey or not

$().SPServices({
            operation: "GetListItems",
            async: false,
            listName: "YOUR SURVEY LISTNAME",
            CAMLQuery: "<Query>" +
                    "<Where>" +
                        "<Eq>" +
                            "<FieldRef Name='Author' LookupId='TRUE' />" +
                            "<Value Type='Lookup'>" + _spPageContextInfo.userId + "</Value>" +
                        "</Eq>" +
                    "</Where>" +
                "</Query>",
            completefunc: function (xData, Status) {
                alert($(xData.responseXML).SPFilterNode("z:row").length);
            }
        })

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.