0

Following method works properly to create list view but I am not able to(don't know) add/select columns in that view, in the same REST API call.

Please Help.

$.ajax
({url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('List Name')/views",
type: "POST",
data: "{'__metadata':{'type': 'SP.View'},'ViewType': 'HTML','Title':'view name','PersonalView':false}",            
            headers:
            {
        "Accept": "application/json;odata=verbose", 
            "Content-Type": "application/json;odata=verbose", 
                "X-RequestDigest": $("#__REQUESTDIGEST").val()
            },
            success: function (data, status, xhr) {               
                  console.log("Success");
            },
            error: function (xhr, status, error) {
                console.log("Failed");
            }        
});
0

In the body/data you have to pass CAML Query like given below on which your view will be created.

"{ '__metadata': { 'type': 'SP.View' }, 'Title': 'View Name', 'PersonalView':   true, 'ViewQuery':'" + query + "'  }";

Reference:

Create List View using SharePoint REST API.

| improve this answer | |
  • ViewQuery is used to filter the view. I want to specify the set of columns for the view. – SharePoint Essential Mar 19 '19 at 17:14
0

you can use addviewfiled in the API URI much like : _api/web/lists(guid)/views(guid)/viewfields/addviewfield('Title')

| improve this answer | |

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.