Skip to main content

Blogging about SharePoint

Go Search
Home
Blogging about SharePoint
Public Speaking
  

Michael Blumenthal's BlumenthalIT.NET > Blogging about SharePoint > Posts > Modifying a web part’s unnamed view with POSH
Modifying a web part’s unnamed view with POSH

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."

}

Comments

There are no comments yet for this post.
Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Body *


Please put your name at the end of your comment as the Name field doesn't display in the main view of the comments.

Name: *


Your name.  If you first name is Michael, please provide initials or the like to clearly distinguish your name from Michael Blumenthal's.
Also, this field does not appear in the main view of the comments.

Need Paid Consulting Services?

Are you interested in engaging a SharePoint consultant for fee-based consulting services?  If so, I can have an Account Executive from my employer contact you.  Other site visitors will not see this column.

Additional Contact Information

Please provide additional contact information if you need a direct response.  Other site visitors will not see this column.

What is tomorrow's date? *

This is a weak CAPTCHA based on advice from a tweet from @ToddKlindt.
Attachments