SPDataStore.CreateScorecard Method
Saves a scorecard object as a content type in a SharePoint list.
Namespace: Microsoft.PerformancePoint.Scorecards.Store
Assembly: Microsoft.PerformancePoint.Scorecards.Store (in Microsoft.PerformancePoint.Scorecards.Store.dll)
Syntax
'Declaration
Public Function CreateScorecard ( _
listUrl As String, _
newElement As Scorecard _
) As Scorecard
'Usage
Dim instance As SPDataStore
Dim listUrl As String
Dim newElement As Scorecard
Dim returnValue As Scorecard
returnValue = instance.CreateScorecard(listUrl, _
newElement)
public Scorecard CreateScorecard(
string listUrl,
Scorecard newElement
)
Parameters
listUrl
Type: System.StringThe server-relative URL of the SharePoint list to save the object to. Example: /BI Center/Lists/PerformancePoint Content.
newElement
Type: Microsoft.PerformancePoint.Scorecards.ScorecardThe scorecard object to save, which specifies a value for the required Name property.
Return Value
Type: Microsoft.PerformancePoint.Scorecards.Scorecard
The new object, which contains updated information such its location and version number.
Implements
IBIMonitoringStore.CreateScorecard(String, Scorecard)
Examples
The following code example shows how to use a private method to create a scorecard and to call CreateScorecard(String, Scorecard) to save it to the repository.
Before you can compile this code example, you must do the following:
Configure your development environment and create a C# class library project in Visual Studio. For information about configuring a development environment, see Setting Up the Development Environment for SharePoint 2010 on Windows Vista, Windows 7, and Windows Server 2008.
Add the Microsoft.PerformancePoint.Scorecards.Client, Microsoft.PerformancePoint.Scorecards.ServerCommon, Microsoft.PerformancePoint.Scorecards.Store, and System.Drawing DLLs as references to your project. For more information about PerformancePoint Services in Microsoft SharePoint Server 2010 DLLs, see PerformancePoint Services DLLs Used in Development Scenarios.
Add the following using directives to your class.
using Microsoft.PerformancePoint.Scorecards; using Microsoft.PerformancePoint.Scorecards.Store; using System.Drawing;
// Create a scorecard that contains two KPIs, based on the following parameters:
// - scorecardName is the name for the scorecard.
// - listUrl is the server-relative URL of the list to save the scorecard to. Example:
// "/BI Center/lists/PerformancePoint Content"
// - kpi1 is the first KPI.
// - kpi2 is the second KPI.
// This method returns the new scorecard.
private Scorecard CreateScorecard(string scorecardName, string listUrl, Kpi kpi1, Kpi kpi2)
{
if (String.IsNullOrEmpty(scorecardName))
throw new ArgumentException("The name must not be null or empty.");
if (String.IsNullOrEmpty(listUrl))
throw new ArgumentException("The list URL must not be null or empty.");
if (null == kpi1)
throw new ArgumentNullException("kpi1");
if (null == kpi2)
throw new ArgumentNullException("kpi2");
// Create a reference to the global data store for convenience.
SPDataStore globalStore = SPDataStore.GlobalDataStore;
List<string> actualHeaders = new List<string>();
List<string> targetHeaders = new List<string>();
Scorecard newScorecard = Scorecard.CreateNew();
newScorecard.Name.Text = scorecardName;
newScorecard.Description.Text = "Created with the SDK.";
// Define the fonts and colors for the grid.
Font scFont = new Font(FontFamily.GenericSansSerif, 9);
newScorecard.ConfiguredView = ConfiguredView.CreateDefaultConfiguredView(
scFont,
Color.White,
Color.Black,
Color.LightSteelBlue,
Color.Bisque,
Color.DimGray);
KpiCollection kpis = new KpiCollection();
kpis.Add(kpi1);
kpis.Add(kpi2);
GridViewDefinition gvd = newScorecard.ConfiguredView.GridViewDefinition;
foreach (Kpi includedKpi in kpis)
{
// Add the KPIs to the scorecard.
GridHeaderItem rowItem = GridHeaderItem.CreateKpiHeader(includedKpi.Location);
gvd.RootRowHeader.Children.Add(rowItem);
// Find unique actuals.
for (int i = 0; i < includedKpi.Actuals.Count; i++)
{
if (!actualHeaders.Contains(includedKpi.Actuals[i].Name.Text))
{
actualHeaders.Add(includedKpi.Actuals[i].Name.Text);
}
}
// Find unique targets.
for (int i = 0; i < includedKpi.Targets.Count; i++)
{
if (!targetHeaders.Contains(includedKpi.Targets[i].Name.Text))
{
targetHeaders.Add(includedKpi.Targets[i].Name.Text);
}
}
}
// Add the actual headings to the scorecard.
foreach (string actualHeader in actualHeaders)
{
GridHeaderItem actualItem = GridHeaderItem.CreateActualHeader(actualHeader);
gvd.RootColumnHeader.Children.Add(actualItem);
}
// Add the target headings to the scorecard.
foreach (string targetHeader in targetHeaders)
{
GridHeaderItem targetItem = GridHeaderItem.CreateTargetHeader(targetHeader);
gvd.RootColumnHeader.Children.Add(targetItem);
}
gvd.RootColumnHeader.LinkTreeFromRoot();
gvd.RootRowHeader.LinkTreeFromRoot();
// Call the CreateScorecard method to save the new scorecard to the specified list.
// TODO: Handle exceptions from this call.
return globalStore.CreateScorecard(listUrl, newScorecard);
}