Thursday, April 5, 2012

SharePoint Designer 2010 and PerformancePoint Web Part Connections (Part 2)

Part 1, Part 2, Part 3

In Part 1 of this post, I provided a function that can reconnect PerformancePoint Services (PPS) web parts as an alternative to having to reconnect the web parts via the browser. This can come in handy when you've lost all of your PPS connections after having saved your web part page in SharePoint Designer.

In this post, I'm providing a function, Create-IFilterValues-To-ITransformableFilterValues-Connection, that can connect a SharePoint Filter to PPS web parts. I had to create this function to connect Query String (URL) Filters (QSUF) to my PPS web parts. Now this wasn't totally necessary, as these connections are not destroyed by saving your page in SharePoint Designer, but I have used it in various scenarios (e.g. deployment, creating new pages from existing) and it is referenced in the function that I'll provide in Part 3.

An example of connecting a QSUF to a PPS SSRS report:

try
{
    $web = Get-SPWeb "http://servername/sitecollectionname/webname"
    $wpm = $web.GetLimitedWebPartManager("http://servername/sitecollectionname/webname/DashboardPages/demo.aspx", [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

    # Report: Share by Market Scatter Plot To Area Filter
    $params = @{
        wpm = $wpm
        wpConsumerTitle ="Report: Share by Market Scatter Plot"
        wpProviderTitle ="Area Filter"
        mappedConsumerParameterName ="SqlReportViewUniqueParameterIdSI4"
        reconnect = $False
    }
    Create-IFilterValues-To-ITransformableFilterValues-Connection @params
}
catch [Exception]
{
    write-host $_.Exception.ToString() -ForegroundColor Red
}
finally
{
    $wpm.Dispose()
    $web.Dispose()
}
Here is the function in its entirety:

function Create-IFilterValues-To-ITransformableFilterValues-Connection {
    param(
        [Parameter(mandatory=$true)] $wpm,
        [Parameter(mandatory=$true)] [string]$wpConsumerTitle,
        [Parameter(mandatory=$true)] [string]$wpProviderTitle,
        [Parameter(mandatory=$true)] [string]$mappedConsumerParameterName,
        [bool]$reconnect=$false
    )
    
     try
    {
        $foundConnection = $false
        
        $wpConnections = $wpm.SPWebPartConnections

        # find connection
        foreach ($wpc in $wpConnections)
        {
            if ($wpc.Consumer.Title -eq $wpConsumerTitle -and $wpc.Provider.Title -eq $wpProviderTitle)
            {
                if ($reconnect -ne $true) {
                    $foundConnection = $true
                }
                else {
                    $wpm.SPDisconnectWebParts($wpc)
                }
                break
            }
        }

        if($foundConnection -eq $false)
        {
            # get consumer and provider web parts
            $wpConsumer = $wpm.WebParts | Where {$_.Title -eq "$wpConsumerTitle"}
            $wpProvider = $wpm.WebParts | Where {$_.Title -eq "$wpProviderTitle"}
 
            # get consumer and provider connection points
             $consumerConnectionPoint = $wpm.GetConsumerConnectionPoints($wpConsumer)["IFilterValues"]
             $providerConnectionPoint = $wpm.GetProviderConnectionPoints($wpProvider)["ITransformableFilterValues"]

             if($consumerConnectionPoint -ne $null -and $providerConnectionPoint -ne $null)
             {
                 $transformer = New-Object Microsoft.SharePoint.WebPartPages.TransformableFilterValuesToFilterValuesTransformer
                 $transformer.MappedConsumerParameterName = $mappedConsumerParameterName

                 # connect the web parts
                 $wpConnection = $wpm.SPConnectWebParts($wpProvider, $providerConnectionPoint, $wpConsumer, $consumerConnectionPoint, $transformer) 

                 write-host "Successfully connected: $wpConsumerTitle, $wpProviderTitle" -ForegroundColor Green
             }
             else
             {
                 write-host "Web parts did not have supported ITransformableFilterValues-To-IFilterValues connection types: $wpConsumerTitle, $wpProviderTitle" -ForegroundColor Green
             }
        }
        else
        {
             write-host "Connection already exists: $wpConsumerTitle, $wpProviderTitle" -ForegroundColor DarkCyan
        }
    }
    catch [Exception]
    {
        write-host $_.Exception.ToString() -ForegroundColor Green
    }
    finally
    {
    }    
}
In Part 3 of this post, I'll provide a function that uses the functions from Part 1 and this part to create a connection script for you when you provide it a web part page full of connections.

4 comments:

  1. Great stuff Ken.

    I'm wondering if you can help me. Using the script here, I've tried connecting a Query String Filter and an XSLT view List, but I get the "Web parts did not have supported ITransformableFilterValues-To-IFilterValues connection types" error

    It seems that the consumer only has a connection point id of

    DFWP Parameter Consumer ID

    While the provider is fine with
    ITransformableFilterValues

    Any idea how to connect these two?

    Thanks,
    Mark

    ReplyDelete
  2. Hi Mark,

    I have not had the opportunity to filter a DFWP in any of my dashboards yet, so I haven't run across this problem. It's also been awhile since I've written these scripts (although I use them all of the time). I'm assuming the DFWP doesn't implement the IFilterValues interface, so you would need to write a function similar to the above that would support it's connection provider.

    I wrote the function in the following reply to discover connection info. If you can run this against the connection that you manually created between your DFWP and QSUF, it should identify the connectionID that the DFWP supports.

    ReplyDelete
    Replies
    1. function Get-Connection-Info {
      param(
      [Parameter(mandatory=$true)] $wpm,
      [Parameter(mandatory=$true)] [string]$wpConsumerTitle,
      [Parameter(mandatory=$true)] [string]$wpProviderTitle
      )

      $foundConnection = $false

      try
      {
      $wpConnections = $wpm.SPWebPartConnections

      write-host "Checking "$wpConnections.Count " connection(s) on web part page."

      foreach ($wpc in $wpConnections)
      {
      if ($wpc.Consumer.Title -eq $wpConsumerTitle -and $wpc.Provider.Title -eq $wpProviderTitle)
      {
      $foundConnection = $true
      break
      }
      }

      if ($foundConnection)
      {
      write-host "Connection found: $wpProviderTitle, $wpConsumerTitle" -ForegroundColor Green

      # Connection
      write-host "Connection Properties:" -ForegroundColor Green
      $wpc | Select *

      # Consumer
      $wpConsumer = $wpc.Consumer
      write-host "Consumer Properties:" -ForegroundColor Green
      $wpConsumer | Select *

      # Consumer Connection Points
      $consumerConnectionPoints = $wpm.GetConsumerConnectionPoints($wpConsumer)
      write-host "Consumer Connection Points:" $consumerConnectionPoints.Count -ForegroundColor Green
      foreach ($cp in $consumerConnectionPoints) {$cp | Select *}

      # Provider
      $wpProvider = $wpc.Provider
      write-host "Provider Properties:" -ForegroundColor Green
      $wpProvider | Select *

      # Recursively examine the object to a depth of 5
      #write-host "Provider Properties (recursive):" -ForegroundColor Green
      #$wpProvider | Format-Custom -Property * -Depth 5 | out-default

      # Provider Connection Points
      $providerConnectionPoints = $wpm.GetProviderConnectionPoints($wpProvider)
      write-host "Provider Connection Points:" $providerConnectionPoints.Count -ForegroundColor Green
      foreach ($cp in $providerConnectionPoints) {$cp | Select *}

      # Transformer
      write-host "Transformer Properties" -ForegroundColor Green
      $wpc.Transformer | Select *

      write-host "Transformer ConfigurationState Properties:" -ForegroundColor Green
      $wpc.Transformer.ConfigurationState | Select *

      write-host "Transformer ConfigurationState ProviderConsumerTransformations Properties:" -ForegroundColor Green
      $wpc.Transformer.ConfigurationState.ProviderConsumerTransformations | Select *
      #$wpc.Transformer.ConfigurationState.ProviderConsumerTransformations | Get-Member -MemberType Method

      foreach($record in $wpc.Transformer.ConfigurationState.ProviderConsumerTransformations.Records)
      {
      write-host "Transformer ConfigurationState ProviderConsumerTransformations Record Properties:" -ForegroundColor Green
      $record | Select *
      }

      write-host "Transformer ConfigurationState ConditionalVisibilityRecord Properties:" -ForegroundColor Green
      $wpc.Transformer.ConfigurationState.ConditionalVisibilityRecord | Select *

      #$wpc.Transformer.ConfigurationState.ConditionalVisibilityRecord.VisibilitySelections | Get-Member
      }
      else
      {
      write-host "Connection not found: $wpProviderTitle, $wpConsumerTitle" -ForegroundColor Red
      }
      }
      catch [Exception]
      {
      write-host $_.Exception.ToString() -ForegroundColor Red
      }
      }

      Delete
  3. This can come in handy when you've lost all of your PPS connections after having saved your web part page in SharePoint Designer. Web Design

    ReplyDelete