November 2009 - Posts

Modifying a web part’s unnamed view with POSH
06 November 09 06:52 PM | Blogging about SharePoint: Posts
Body:

Here’s a little POSH script I wrote today, generalized a bit.

The web part in question shows a list that has a column named “Title”, and one named “Percentage”, where it grouped them by a column called MarketType.

It started out sorting ascending by title, and afterwards sorts descending by percentage.

 

function global:Sort-WPBiggestPercentOnTop($SPViewUsedByWP)

{

$oldqu = $SPViewUsedByWP.Query

if $oldqu -ne "<GroupBy Collapse=""FALSE"" GroupLimit=""100""><FieldRef Name=""Market_x0020_Type"" Ascending=""FALSE"" /></GroupBy><OrderBy><FieldRef Name=""Title"" /></OrderBy>"

{ write-error "View not as expected"}

$newqu = $oldqu.Replace("<FieldRef Name=""Title"" />","<FieldRef Name=""Percentage"" Ascending=""FALSE"" />"

$SPViewUsedByWP.Query = $newqu

$SPViewUsedByWP.Update()

write-host "Need to reset the state of the web part toolbar, it gets changed when the view gets edited."

}

Category: PowerShell and SharePoint
Published: 11/6/2009 3:52 PM
Del.icio.us | Digg It | Technorati | Blinklist | Furl | reddit | DotNetKicks