0

Provided following body content for a SharePoint REST api call:

{
  '__metadata': { 'type': 'SP.View' },
  'Title': 'Awesome View',
  'PersonalView': false
}

This creates a new view named Amesome View for the list on which the api call is executed. The type of this view will be a default view.

My question is: is there a way to create a datasheet view using the REST api?

I have found nothing on this and I searched for the SharePoint Client ViewType property on MSDN, and it shows that this is a get property, no set available.

So, using CSOM it won't be possible at all I assume. I've also tried providing the ViewType property, just to be sure:

{
  '__metadata': { 'type': 'SP.View' },
  'Title': 'Awesome View',
  'PersonalView': false,
  "ViewType": "GRID"
}

The GRID value comes from the ViewType enumeration. (Also tried using the in value or lower-case). But all this didn't work.

So, is there a way to achieve this through the REST api?

Edit:

To clarify: sadly, CSOM or PowerShell are not an option.

  • Check this Link : Sharepoint view list item – Ali varzeshi Mar 27 '18 at 9:58
  • @Alivarzeshi Did you read the question properly? I want to create a view, not get items from a specific view. – Abbas Mar 27 '18 at 10:06
0

I don't really understand if you are able to use CSOM or must use REST. But when reading on msdn there is a class namned ViewCreationInformation which has a ViewTypeKind Property which is get/set.

But no it does not seem to be a way to do this when using the REST api.

Here is an example using PowerShell

$list = Get-PnPList -Identity "testlist" #Im using PnP to get the list.

$vci = New-Object Microsoft.SharePoint.Client.ViewCreationInformation
$vci.Title = "My Awsome View"
$vci.PersonalView = $true
$vci.ViewTypeKind = [Microsoft.SharePoint.Client.ViewType]::Grid

#Add some fields to show in view
$vci.ViewFields = [string[]]@("Title","flightnr")

$view = $list.Views.Add($vci)

$list.Update()

$list.Context.ExecuteQuery()

Which results in the following view:

My awsome view

  • Thanks for your answerr. In my situation it has to be REST, no other option (updated my question). Would the ViewTypeKind property available/working in REST? – Abbas Mar 8 '18 at 8:24
  • @Abbas no i don't think so. What I can see there is no way of setting ViewTypeKind using the REST api. – Johan Brännmar Mar 8 '18 at 8:31
0

Search this : Create a view in this link POST request example: Create a view

When you create a view, the server returns the view. To add, remove, or change the order of view fields for the new view, use the ViewFieldCollection methods.

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.