【问题标题】:Sharepoint - Create view with grouping and list item hyperlink using Powershell CSOMSharepoint - 使用 Powershell CSOM 创建包含分组和列表项超链接的视图
【发布时间】:2015-10-20 14:16:56
【问题描述】:

我正在使用 powershell 创建一个视图。

下面是包含视图和列表名称列的 XML 文件。

<Views>
  <View List="Emp List" Title="EMP Requests" >
    <Field Name="EmpName"/>
    <Field Name="Status"/>
    <Field Name="Emp ID"/>
    <Field Name="Date of Joining"/>
  </View>
</Views>

以下是创建视图的 Powershell 代码(CSOM):

[xml]$ViewDef               =    Get-Content -Path "C:\.....XML File Path\CompletedReqView.xml"

$context = New-Object Microsoft.SharePoint.Client.ClientContext("----URL Goes Here ----") 
$context.Credentials = $credentials
$web=$context.Web;
$context.Load($web)
$context.ExecuteQuery()
Write-Host "Creating View" -foregroundcolor white -backgroundcolor Yellow 
    foreach($view in $ViewDef.Views.View)
    {
        $List = $context.Web.Lists.GetByTitle($view.List)
        $context.Load($List)
        $context.ExecuteQuery()

        $View=$List.Views
        $context.Load($View)
        $context.ExecuteQuery()

        $ViewFields = New-Object System.Collections.Specialized.StringCollection

        foreach($field in $view.Field){
            $ViewFields.Add($field.Name)
        }

        $ViewQuery = "<Where><Eq><FieldRef Name='Status' /><Value Type='Text'>Done</Value></Eq></Where>"

        $ViewInfo = New-Object Microsoft.SharePoint.Client.ViewCreationInformation
        $ViewInfo.ViewTypeKind =[Microsoft.SharePoint.Client.ViewType]::Html
        $ViewInfo.Query = $compReqViewQuery   
        $ViewInfo.RowLimit = 50
        $ViewInfo.ViewFields = $compReqViewFields
        $ViewInfo.Title = $view.Title
        $ViewInfo.Paged = $true
        $ViewInfo.PersonalView = $false

        $addi=$List.Views.Add(ViewInfo)
        $context.Load($List)
        try
        {
            $context.ExecuteQuery()

        }
        catch
        {
            Write-Host "Error : $_.Exception.Message" -foregroundcolor white -backgroundcolor Red 
            return
        }
    }

使用上面的代码,我能够成功地创建一个视图。 我在这里面临两个问题:

  1. Group By:如何在此视图中执行 groupby。假设我希望数据按“状态”列分组。 我尝试在 caml 查询中给出 Group By(上面代码中的 $ViewQuery),但分组不起作用。 这个分组是否应该作为一个属性给出?

  2. 我希望“名称”列中的列表项为超链接,如何实现?

请提出建议。

【问题讨论】:

    标签: powershell sharepoint powershell-3.0 csom custom-lists


    【解决方案1】:

    要获得分组,您需要更新 CAML 查询以包含按元素分组。如果它不起作用,您需要确保您的 CAML 格式正确。我建议使用 CAML 查询工具。

    <GroupBy Collapse=\"True\" GroupLimit=\"300\">Your field ref in here</groupBy>
    

    我不确定链接周围,如果我希望它是一个超链接,我会使用 xsltview Web 部件并自定义 xslt。

    干杯

    真人

    【讨论】:

      猜你喜欢
      • 2016-09-06
      • 2018-01-03
      • 2017-11-23
      • 2017-04-04
      • 2017-08-19
      • 2010-10-18
      • 2014-03-13
      • 2017-02-08
      • 2018-01-28
      相关资源
      最近更新 更多