Build Survey Edit View link by PowerShell
For some reason there were removed links to create View for SharePoint Surveys. When we want to create new view for survey, we go to Survey Settings page and replace survedit in url by ViewType. On that page we can create new view, but we have no access to edit it later. Script bellow generates link to be able to edit this created view.
Here is the script, how to build Edit View link. You can just paste this link to the browser
Add-PSSnapin microsoft.sharepoint.powershell -ea 0
$webUrl = "https://mysitecollection"
$listName = "MyList"
$viewName = "MyTestView"
$web = Get-SPWeb $webUrl
$list = $web.Lists[$listName]
#$list.Fields | select InternalName, Title
$view = $list.Views | where {$_.Title -match $viewName}
$view.Title
$view.ParentList.ID
$view.ID
function UrlEncode($url)
{
$encodedUrl = [System.Web.HttpUtility]::UrlEncode($url)
$encodedUrl = $encodedUrl.Replace("-", "%2D");
return $encodedUrl
}
$viewId = UrlEncode $view.ID.ToString()
$listId = UrlEncode $list.ID.ToString()
#$settingsUrl = UrlEncode ($webUrl + "/_layouts/15/Survedit.aspx?List=" + $list.ID)
$settingsUrl = UrlEncode ("https://www.google.com")
"---------"
#ViewId to string must be surroundet by %7B, %7D
#ViewId must be by capitals
#In case one of these conditions is not fulfilled, edit link shows ViewEdit.aspx, but throws error when saving, that View doesn't exist
#If source query parameter is not used, user is redirected to view
$editViewUrlEncoded = $webUrl + "/_layouts/15/ViewEdit.aspx?List=" + $listId + "&View=%7B" + $viewId.ToUpper() + "%7D"
$editViewUrlEncoded