Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
こんにちは SharePoint サポートの森 健吾 (kenmori) です。
今回の投稿では、SharePoint Online のブログ サイトで、ページのカスタマイズなどを実施していて、カテゴリやアーカイブ フィルターが正常に動作しなくなった際の対処策をお伝えいたします。
目次
現象 1 : ブログ サイトのトップから、カテゴリやアーカイブをクリックしても、絞り込みされない
現象 2 : カテゴリをクリックしても絞り込みされず、カテゴリ リストやトップページに遷移する
現象 1 : ブログ サイトのトップから、カテゴリやアーカイブをクリックしても、絞り込みされない
上記画面のとおり、画面左のカテゴリから [アイデア] をクリックしても、フィルターが効いておらず、画面右側でアイデア以外の投稿 (例. 意見) も表示されています。
原因
何らかの操作により、ビューに定義されているクエリ情報が書き換えられたことに起因します。カテゴリーやアーカイブ フィルターを実現するためには、ページ表示時にHTTP 要求 URL のクエリ文字列で渡されたパラメーターをビューが読み取ってフィルターに使用します。
例)
・Category.aspx?CategoryId=2
・Date.aspx?StartDateTime=2015%2D10%2D31T15%3A00%3A00Z&EndDateTime=2015%2D11%2D22T20%3A49%3A19Z&LMY=2015%E5%B9%B411%E6%9C%88
しかし、標準のビューの編集画面ではクエリ文字列を受け取るような設定はできませんので一度でも設定画面で [OK] などを押してしまうと、クエリ文字列フィルターは除去されてしまいます。
これに対して、最近では画面操作では、カテゴリやアーカイブ フィルターされたビューを編集できないようブロックされたこともあり、このようなミスオペレーションが発生しにくくなっております。
それでもSharePoint Designer や PowerShell などを経由しては可能であるため、変更が全くできなくなったわけではありません。
上記のとおり、標準のビュー編集画面にはない機能を使用しているため、画面操作だけで復旧することが困難な状況です。対処策として有効な PowerShell コードを共有します。
実行手順
1. テキスト エディターを開き、下記内容を FixBlogSiteView.ps1 などとして保存します。
param (
$siteUrl,
$username,
$password,
$force = $false
)
$ErrorActionPreference = "Stop"
[void][System.Reflection.Assembly]::Load("Microsoft.SharePoint.Client, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
[void][System.Reflection.Assembly]::Load("Microsoft.SharePoint.Client.Runtime, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
$context = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$pwd = convertto-securestring $password -AsPlainText -Force
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $pwd)
$context.Credentials = $credentials
$web = $context.Web
$context.Load($web)
$context.Load($web.Lists)
$context.ExecuteQuery()
foreach ($list in $web.Lists)
{
$context.Load($list)
$context.Load($list.Views)
$context.ExecuteQuery()
if ($list.BaseTemplate -eq 301)
{
$removefiles = new-object System.Collections.ArrayList
foreach ($view in $list.Views)
{
$context.Load($view)
$context.ExecuteQuery()
if ($view.ServerRelativeUrl -like "*Category.aspx")
{
if ($force)
{
$web.GetFileByServerRelativeUrl($view.ServerRelativeUrl).DeleteObject()
}
else
{
$view.ViewQuery = "<OrderBy><FieldRef Name=""PublishedDate"" Ascending=""FALSE"" /><FieldRef Name=""ID"" Ascending=""FALSE"" /></OrderBy><Where><And><And><In><FieldRef Name=""PostCategory"" LookupId=""TRUE"" /><Values><Value Type=""Integer""><IfEqual><Expr1><GetVar Scope=""Request"" Name=""CategoryId"" /></Expr1><Expr2 /><Then>-1</Then><Else><GetVar Scope=""Request"" Name=""CategoryId"" /></Else></IfEqual></Value></Values></In><Leq><FieldRef Name=""PublishedDate"" /><Value Type=""DateTime""><Today /></Value></Leq></And><Eq><FieldRef Name=""_ModerationStatus"" /><Value Type=""ModStat"">0</Value></Eq></And></Where>"
$view.Update()
}
}
if ($view.ServerRelativeUrl -like "*Date.aspx")
{
if ($force)
{
$web.GetFileByServerRelativeUrl($view.ServerRelativeUrl).DeleteObject()
}
else
{
$view.ViewQuery = "<OrderBy><FieldRef Name=""PublishedDate"" Ascending=""FALSE"" /><FieldRef Name=""ID"" Ascending=""FALSE"" /></OrderBy><Where><And><And><Geq><FieldRef Name=""PublishedDate"" /><Value Type=""DateTime"" IncludeTimeValue=""TRUE"" StorageTZ=""TRUE""><GetVar Scope=""Request"" Name=""StartDateTime"" /></Value></Geq><Lt><FieldRef Name=""PublishedDate"" /><Value Type=""DateTime"" IncludeTimeValue=""TRUE"" StorageTZ=""TRUE""><GetVar Scope=""Request"" Name=""EndDateTime"" /></Value></Lt></And><Eq><FieldRef Name=""_ModerationStatus"" /><Value Type=""ModStat"">0</Value></Eq></And></Where>"
$view.Update()
}
}
if ($view.ServerRelativeUrl -like "*Post.aspx")
{
if ($force)
{
$web.GetFileByServerRelativeUrl($view.ServerRelativeUrl).DeleteObject()
}
else
{
$view.ViewQuery = "<OrderBy><FieldRef Name=""PublishedDate"" Ascending=""FALSE"" /><FieldRef Name=""ID"" Ascending=""FALSE"" /></OrderBy><Where><Eq><FieldRef Name=""ID"" /><Value Type=""""><GetVar Scope=""Request"" Name=""ID"" /></Value></Eq></Where>"
$view.Update()
}
}
}
}
$context.ExecuteQuery()
}
if ($force)
{
$blogsiteguid = new-object system.guid("0D1C50F7-0309-431c-ADFB-B777D5473A65")
$feature = $web.Features.Add($blogsiteguid, $force, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None)
$context.ExecuteQuery()
#下記では機能の修復によって重複追加される標準のカテゴリーと投稿を削除しています。
foreach ($list in $web.Lists)
{
$context.Load($list)
$context.ExecuteQuery()
$delitemcnt = 0
if ($list.BaseTemplate -eq 303)
{
$delitemcnt = 3
}
if ($list.BaseTemplate -eq 301)
{
$delitemcnt = 1
}
if ($delitemcnt -gt 0)
{
$camlquery = new-object Microsoft.SharePoint.Client.CamlQuery
$items = $list.GetItems($camlquery)
$context.Load($items)
$context.ExecuteQuery()
$cnt = 0
for ($i = $items.Count - 1; $i -gt 0; $i--)
{
$items[$i].DeleteObject()
$cnt++
if ($cnt -ge $delitemcnt) {break}
}
$context.ExecuteQuery()
}
}
}
2. 下記のようにパラメーターを指定して実行します。
例1) ビュー定義の修復
.\FixBlogSiteView.ps1 -siteUrl https://tenant.sharepoint.com/blogsite -username user@tenant.onmicrosoft.com -password password
例 2) ビューの再作成 (-force $true)
.\FixBlogSiteView.ps1 -siteUrl https://tenant.sharepoint.com/blogsite -username user@tenant.onmicrosoft.com -password password -force $true
パラメータ
-siteUrl ・・・ ブログ サイト URL
-username ・・・ 修復操作を実施するログイン名
-password ・・・ パスワード
-force ・・・ $true の際はビューを再作成。
ただし、-force オプションを使用する際には # 下記では機能の修復によって重複追加される標準のカテゴリーと投稿を削除しています。との記載もある通り、復旧には直接不要な処理まで実行さますので、実行後には既存コンテンツに影響が及ばないか十分に確認する必要があります。
現象 2 : カテゴリをクリックしても絞り込みされず、カテゴリ リストやトップページなどに遷移する
上記画面で [アイデア] をクリックすると、カテゴリーが "アイデア" でフィルターされた投稿リストが表示されず、カテゴリのビューに遷移しています。
発生原因は簡単でブログ ツール Web パーツが画面上から消えていることに起因します。
あわてず、[ページの編集] 画面から "ブログ ツール" Web パーツを再度追加すれば復旧完了です。
※ 注意
ブログ ツール Web パーツは SharePoint Designer での編集に対応していません。ページを上書き保存しただけで、下記のとおりエラーになります。
この際に現象 2 も発生します。SPD で編集を加える際は、エラーになったブログ ツール Web パーツを一度削除し、ページに再配置してください。
今回の投稿は以上になります。