import Global from '../../_global.mdx';
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# spo list view add

Adds a new view to a SharePoint list

## Usage

```sh
m365 spo list view add [options]
```

## Options

```md definition-list
`-u, --webUrl <webUrl>`
: URL of the site where the list is located.

`--listId [listId]`
: ID of the list to which the view should be added. Specify either `listId`, `listTitle`, or `listUrl` but not multiple.

`--listTitle [listTitle]`
: Title of the list to which the view should be added. Specify either `listId`, `listTitle`, or `listUrl` but not multiple.

`--listUrl [listUrl]`
: Relative URL of the list to which the view should be added. Specify either `listId`, `listTitle`, or `listUrl` but not multiple.

`--title <title>`
: Title of the view to be created for the list.

`--type [type]`
: Type of the view. Possible values are: `list`, `calendar`, `gallery`, `kanban`. Defaults to `list`.

`--fields [fields]`
: Comma-separated list of **case-sensitive** internal names of the fields to add to the view. Optional when `type` is set to `calendar`.

`--viewQuery [viewQuery]`
: XML representation of the list query for the underlying view.

`--calendarStartDateField [calendarStartDateField]`
: Internal name of the field that contains the start date of the calendar event. Required when `type` is set to `calendar`.

`--calendarEndDateField [calendarEndDateField]`
: Internal name of the field that contains the end date of the calendar event. Required when `type` is set to `calendar`.

`--calendarTitleField [calendarTitleField]`
: Internal name of the field that contains the title of the calendar event. Required when `type` is set to `calendar`.

`--calendarSubTitleField [calendarSubTitleField]`
: Internal name of the field that contains the subtitle of the calendar event.

`--calendarDefaultLayout [calendarDefaultLayout]`
: Default layout of the calendar view. Possible values are: `month`, `week`, `workWeek`, `day`. Defaults to `month`.

`--kanbanBucketField [kanbanBucketField]`
: Internal name of the field that contains the bucket for the Kanban board view. Required when `type` is set to `kanban`.

`--personal`
: View will be created as personal view, if specified.

`--default`
: View will be set as default view, if specified.

`--paged [paged]`
: View supports paging. Valid values are `true`, `false`. Defaults to `true`.  

`--rowLimit [rowLimit]`
: Sets the number of items to display for the view. Default value is 30.
```

<Global />

## Remarks

:::tip

We recommend using the `paged` option. Paging is enabled by default: the view shows items page by page, up to the specified `rowLimit` per page. To disable paging, set `paged` to `false`; in a non-paged view, the `rowLimit` is absolute and there is no link to see more items.

:::

## Examples

Add a list view called to a list with specific title.

```sh
m365 spo list view add --webUrl https://contoso.sharepoint.com/sites/Sales --listTitle "Customers" --title "All customers" --fields "LinkTitle,Country,Sector,Country,Address,Contact"
```

Add a gallery view as default view to a list with a specific URL.

```sh
m365 spo list view add --webUrl https://contoso.sharepoint.com/sites/Sales --listUrl "/Lists/Customers" --title "All customers" --type gallery --fields "LinkTitle,Country,Sector,Country,Address,Contact" --default
```

Add a view with defined filter and sorting.

```sh
m365 spo list view add --webUrl https://contoso.sharepoint.com/sites/Sales --listTitle "Customers" --title "Transport customers" --fields "LinkTitle,Country,Country,Address,Contact" --viewQuery "<OrderBy><FieldRef Name='LinkTitle' Ascending='TRUE' /></OrderBy><Where><Eq><FieldRef Name='Sector' /><Value Type='Text'>Transportation</Value></Eq></Where>"
```

Add a gallery view as personal view.

```sh
m365 spo list view add --webUrl https://contoso.sharepoint.com/sites/Sales --listTitle "Customers" --title "All customers" --type gallery --fields "LinkTitle,Country,Sector,Country,Address,Contact" --personal
```

Add a calendar view with month layout.

```sh
m365 spo list view add --webUrl https://contoso.sharepoint.com/sites/Sales --listTitle "Events" --title "All events" --type calendar --fields "EventType,InternalExternal" --calendarStartDateField EventStartDate --calendarEndDateField EventEndDate --calendarTitleField LinkTitle
```

Add a calendar view with week layout and subtitle.

```sh
m365 spo list view add --webUrl https://contoso.sharepoint.com/sites/Sales --listTitle "Events" --title "All events" --type calendar --fields "EventType,InternalExternal" --calendarStartDateField EventStartDate --calendarEndDateField EventEndDate --calendarTitleField LinkTitle --calendarSubTitleField Location --calendarDefaultLayout week
```

Add a Kanban board view.

```sh
m365 spo list view add --webUrl https://contoso.sharepoint.com/sites/Sales --listTitle "Tasks" --title "All tasks" --type kanban --fields "Title,AssignedTo" --kanbanBucketField Status
```

## Response

<Tabs>
  <TabItem value="JSON">

  ```json
  {
    "Aggregations": null,
    "AggregationsStatus": null,
    "AssociatedContentTypeId": null,
    "BaseViewId": null,
    "CalendarViewStyles": null,
    "ColumnWidth": null,
    "ContentTypeId": {
      "StringValue": "0x"
    },
    "CustomFormatter": null,
    "CustomOrder": null,
    "DefaultView": false,
    "DefaultViewForContentType": false,
    "EditorModified": false,
    "Formats": null,
    "GridLayout": null,
    "Hidden": false,
    "HtmlSchemaXml": "<View Type=\"HTML\" Url=\"/Lists/Test/All events.aspx\" Personal=\"FALSE\" DisplayName=\"All events\" DefaultView=\"FALSE\" Name=\"{3CD2E934-F482-4D4A-A9B8-A13B49B3D226}\"><ViewFields><FieldRef Name=\"Title\" /></ViewFields><Query><OrderBy><FieldRef Name=\"Created\" Ascending=\"FALSE\" /></OrderBy><Where><Eq><FieldRef Name=\"TextFieldName\" /><Value Type=\"Text\">Field value</Value></Eq></Where></Query><RowLimit Paged=\"TRUE\">30</RowLimit></View>",
    "Id": "3cd2e934-f482-4d4a-a9b8-a13b49b3d226",
    "ImageUrl": null,
    "IncludeRootFolder": false,
    "ViewJoins": null,
    "JSLink": null,
    "ListViewXml": "<View Type=\"HTML\" Url=\"/Lists/Test/All events.aspx\" Personal=\"FALSE\" DisplayName=\"All events\" DefaultView=\"FALSE\" Name=\"{3CD2E934-F482-4D4A-A9B8-A13B49B3D226}\" ><Query><OrderBy><FieldRef Name=\"Created\" Ascending=\"FALSE\" /></OrderBy><Where><Eq><FieldRef Name=\"TextFieldName\" /><Value Type=\"Text\">Field value</Value></Eq></Where></Query><ViewFields><FieldRef Name=\"Title\" /></ViewFields><RowLimit Paged=\"TRUE\">30</RowLimit><Toolbar Type=\"None\"/></View>",
    "Method": null,
    "MobileDefaultView": false,
    "MobileView": false,
    "ModerationType": null,
    "NewDocumentTemplates": null,
    "OrderedView": false,
    "Paged": true,
    "PersonalView": false,
    "ViewProjectedFields": null,
    "ViewQuery": "<OrderBy><FieldRef Name=\"Created\" Ascending=\"FALSE\" /></OrderBy><Where><Eq><FieldRef Name=\"TextFieldName\" /><Value Type=\"Text\">Field value</Value></Eq></Where>",
    "ReadOnlyView": false,
    "RequiresClientIntegration": false,
    "RowLimit": 30,
    "Scope": 0,
    "ServerRelativePath": {
      "DecodedUrl": "/Lists/Test/All events.aspx"
    },
    "ServerRelativeUrl": "/Lists/Test/All events.aspx",
    "StyleId": null,
    "TabularView": true,
    "Threaded": false,
    "Title": "All events",
    "Toolbar": null,
    "ToolbarTemplateName": null,
    "ViewType": "HTML",
    "ViewData": null,
    "ViewType2": null,
    "VisualizationInfo": null
  }
  ```

  </TabItem>
  <TabItem value="Text">

  ```text
  Aggregations             : null
  AggregationsStatus       : null
  AssociatedContentTypeId  : null
  BaseViewId               : null
  CalendarViewStyles       : null
  ColumnWidth              : null
  ContentTypeId            : {"StringValue":"0x"}
  CustomFormatter          : null
  CustomOrder              : null
  DefaultView              : false
  DefaultViewForContentType: false
  EditorModified           : false
  Formats                  : null
  GridLayout               : null
  Hidden                   : false
  HtmlSchemaXml            : <View Type="HTML" Url="/Lists/Test/All events1.aspx" Personal="FALSE" DisplayName="All events" DefaultView="FALSE" Name="{F037FE93-4C74-4ACB-B7B0-71BA599F13C1}"><ViewFields><FieldRef Name="Title" /></ViewFields><Query><OrderBy><FieldRef Name="Created" Ascending="FALSE" /></OrderBy><Where><Eq><FieldRef Name="TextFieldName" /><Value Type="Text">Field value</Value></Eq></Where></Query><RowLimit Paged="TRUE">30</RowLimit></View>
  Id                       : f037fe93-4c74-4acb-b7b0-71ba599f13c1
  ImageUrl                 : null
  IncludeRootFolder        : false
  JSLink                   : null
  ListViewXml              : <View Type="HTML" Url="/Lists/Test/All events1.aspx" Personal="FALSE" DisplayName="All events" DefaultView="FALSE" Name="{F037FE93-4C74-4ACB-B7B0-71BA599F13C1}" ><Query><OrderBy><FieldRef Name="Created" Ascending="FALSE" /></OrderBy><Where><Eq><FieldRef Name="TextFieldName" /><Value Type="Text">Field value</Value></Eq></Where></Query><ViewFields><FieldRef Name="Title" /></ViewFields><RowLimit Paged="TRUE">30</RowLimit><Toolbar Type="None"/></View>
  Method                   : null
  MobileDefaultView        : false
  MobileView               : false
  ModerationType           : null
  NewDocumentTemplates     : null
  OrderedView              : false
  Paged                    : true
  PersonalView             : false
  ReadOnlyView             : false
  RequiresClientIntegration: false
  RowLimit                 : 30
  Scope                    : 0
  ServerRelativePath       : {"DecodedUrl":"/Lists/Test/All events1.aspx"}
  ServerRelativeUrl        : /Lists/Test/All events1.aspx
  StyleId                  : null
  TabularView              : true
  Threaded                 : false
  Title                    : All events
  Toolbar                  : null
  ToolbarTemplateName      : null
  ViewData                 : null
  ViewJoins                : null
  ViewProjectedFields      : null
  ViewQuery                : <OrderBy><FieldRef Name="Created" Ascending="FALSE" /></OrderBy><Where><Eq><FieldRef Name="TextFieldName" /><Value Type="Text">Field value</Value></Eq></Where>
  ViewType                 : HTML
  ViewType2                : null
  VisualizationInfo        : null
  ```

  </TabItem>
  <TabItem value="CSV">

  ```csv
  Aggregations,AggregationsStatus,AssociatedContentTypeId,BaseViewId,CalendarViewStyles,ColumnWidth,ContentTypeId,CustomFormatter,CustomOrder,DefaultView,DefaultViewForContentType,EditorModified,Formats,GridLayout,Hidden,HtmlSchemaXml,Id,ImageUrl,IncludeRootFolder,ViewJoins,JSLink,ListViewXml,Method,MobileDefaultView,MobileView,ModerationType,NewDocumentTemplates,OrderedView,Paged,PersonalView,ViewProjectedFields,ViewQuery,ReadOnlyView,RequiresClientIntegration,RowLimit,Scope,ServerRelativePath,ServerRelativeUrl,StyleId,TabularView,Threaded,Title,Toolbar,ToolbarTemplateName,ViewType,ViewData,ViewType2,VisualizationInfo
  ,,,,,,"{""StringValue"":""0x""}",,,,,,,,,"<View Type=""HTML"" Url=""/Lists/Test/All events2.aspx"" Personal=""FALSE"" DisplayName=""All events"" DefaultView=""FALSE"" Name=""{0F11C3F1-E174-4A85-93A9-B4AFB7BD41B6}""><ViewFields><FieldRef Name=""Title"" /></ViewFields><Query><OrderBy><FieldRef Name=""Created"" Ascending=""FALSE"" /></OrderBy><Where><Eq><FieldRef Name=""TextFieldName"" /><Value Type=""Text"">Field value</Value></Eq></Where></Query><RowLimit Paged=""TRUE"">30</RowLimit></View>",0f11c3f1-e174-4a85-93a9-b4afb7bd41b6,,,,,"<View Type=""HTML"" Url=""/Lists/Test/All events2.aspx"" Personal=""FALSE"" DisplayName=""All events"" DefaultView=""FALSE"" Name=""{0F11C3F1-E174-4A85-93A9-B4AFB7BD41B6}"" ><Query><OrderBy><FieldRef Name=""Created"" Ascending=""FALSE"" /></OrderBy><Where><Eq><FieldRef Name=""TextFieldName"" /><Value Type=""Text"">Field value</Value></Eq></Where></Query><ViewFields><FieldRef Name=""Title"" /></ViewFields><RowLimit Paged=""TRUE"">30</RowLimit><Toolbar Type=""None""/></View>",,,,,,,1,,,"<OrderBy><FieldRef Name=""Created"" Ascending=""FALSE"" /></OrderBy><Where><Eq><FieldRef Name=""TextFieldName"" /><Value Type=""Text"">Field value</Value></Eq></Where>",,,30,0,"{""DecodedUrl"":""/Lists/Test/All events2.aspx""}",/Lists/Test/All events2.aspx,,1,,All events,,,HTML,,,
  ```

  </TabItem>
  <TabItem value="Markdown">

  ```md
  # spo list view add --webUrl "https://contoso.sharepoint.com" --listTitle "Test" --title "All events" --fields "FieldName1" --viewQuery "<OrderBy><FieldRef Name='Created' Ascending='FALSE' /></OrderBy><Where><Eq><FieldRef Name='TextFieldName' /><Value Type='Text'>Field value</Value></Eq></Where>"

  Date: 2/20/2023

  ## All events (f3cade4a-d8c4-43b3-971c-9a4acc2510b8)

  Property | Value
  ---------|-------
  Aggregations | null
  AggregationsStatus | null
  AssociatedContentTypeId | null
  BaseViewId | null
  CalendarViewStyles | null
  ColumnWidth | null
  CustomFormatter | null
  CustomOrder | null
  DefaultView | false
  DefaultViewForContentType | false
  EditorModified | false
  Formats | null
  GridLayout | null
  Hidden | false
  HtmlSchemaXml | <View Type="HTML" Url="/Lists/Test/All events.aspx" Personal="FALSE" DisplayName="All events" DefaultView="FALSE" Name="{F3CADE4A-D8C4-43B3-971C-9A4ACC2510B8}"><ViewFields><FieldRef Name="FieldName1" /></ViewFields><Query><OrderBy><FieldRef Name="Created" Ascending="FALSE" /></OrderBy><Where><Eq><FieldRef Name="TextFieldName" /><Value Type="Text">Field value</Value></Eq></Where></Query><RowLimit Paged="TRUE">30</RowLimit></View>
  Id | f3cade4a-d8c4-43b3-971c-9a4acc2510b8
  ImageUrl | null
  IncludeRootFolder | false
  ViewJoins | null
  JSLink | null
  ListViewXml | <View Type="HTML" Url="/Lists/Test/All events.aspx" Personal="FALSE" DisplayName="All events" DefaultView="FALSE" Name="{F3CADE4A-D8C4-43B3-971C-9A4ACC2510B8}" ><Query><OrderBy><FieldRef Name="Created" Ascending="FALSE" /></OrderBy><Where><Eq><FieldRef Name="TextFieldName" /><Value Type="Text">Field value</Value></Eq></Where></Query><ViewFields><FieldRef Name="FieldName1" /></ViewFields><RowLimit Paged="TRUE">30</RowLimit><Toolbar Type="None"/></View>
  Method | null
  MobileDefaultView | false
  MobileView | false
  ModerationType | null
  NewDocumentTemplates | null
  OrderedView | false
  Paged | true
  PersonalView | false
  ViewProjectedFields | null
  ViewQuery | <OrderBy><FieldRef Name="Created" Ascending="FALSE" /></OrderBy><Where><Eq><FieldRef Name="TextFieldName" /><Value Type="Text">Field value</Value></Eq></Where>
  ReadOnlyView | false
  RequiresClientIntegration | false
  RowLimit | 30
  Scope | 0
  ServerRelativeUrl | /Lists/Test/All events.aspx
  StyleId | null
  TabularView | true
  Threaded | false
  Title | All events
  Toolbar | null
  ToolbarTemplateName | null
  ViewType | HTML
  ViewData | null
  ViewType2 | null
  VisualizationInfo | null
  ```

  </TabItem>
</Tabs>
