Share via


SPDataStore.CreateKpi - Méthode

Enregistre un objet d'indicateur de performance clé performances sous la forme d'un type de contenu dans une liste SharePoint.

Espace de noms :  Microsoft.PerformancePoint.Scorecards.Store
Assembly :  Microsoft.PerformancePoint.Scorecards.Store (dans Microsoft.PerformancePoint.Scorecards.Store.dll)

Syntaxe

'Déclaration
Public Function CreateKpi ( _
    listUrl As String, _
    kpi As Kpi _
) As Kpi
'Utilisation
Dim instance As SPDataStore
Dim listUrl As String
Dim kpi As Kpi
Dim returnValue As Kpi

returnValue = instance.CreateKpi(listUrl, _
    kpi)
public Kpi CreateKpi(
    string listUrl,
    Kpi kpi
)

Paramètres

  • listUrl
    Type : System.String

    L'URL relative de serveur de la liste SharePoint pour enregistrer l'objet. Exemple : /BI Center/Lists/PerformancePoint Content.

Valeur renvoyée

Type : Microsoft.PerformancePoint.Scorecards.Kpi
Le nouvel objet, qui contient des informations mises à jour ce son numéro de version et d'emplacement.

Implémentations

IBIMonitoringStore.CreateKpi(String, Kpi)

Exemples

Les exemples de code suivants montrent comment utiliser une méthode privée pour créer un indicateur de performance clé et d'appeler CreateKpi(String, Kpi) pour l'enregistrer dans le référentiel. Le premier exemple crée un indicateur de performance clé avec fixe réel et les valeurs cibles et le deuxième exemple crée un indicateur de performance clé qui utilise une source de données OLAP.

Pour pouvoir compiler ces exemples de code, vous procédez comme suit :

  • Configurer votre environnement de développement et créer un projet de bibliothèque de classes c# dans Visual Studio. Pour plus d'informations sur la configuration d'un environnement de développement, voir Configurer un environnement de développement général pour SharePoint 2013.

  • Ajoutez les DLL de Microsoft.PerformancePoint.Scorecards.Store, Microsoft.PerformancePoint.Scorecards.ServerCommon et Microsoft.PerformancePoint.Scorecards.Client en tant que références à votre projet. Pour plus d'informations sur PerformancePoint Services DLL, voir PerformancePoint Services DLLs Used in Development Scenarios.

  • Ajoutez les directives using suivantes à votre classe.

    using Microsoft.PerformancePoint.Scorecards;
    using Microsoft.PerformancePoint.Scorecards.Indicators;
    using Microsoft.PerformancePoint.Scorecards.Store;
    
// Create a KPI that uses fixed values for the actual and target values, based on the following parameters:
//   - kpiName is the name for the KPI.
//   - listUrl is the server-relative URL of the list to save the KPI to.
//         Example: "/BI Center/Lists/PerformancePoint Content"
// This method returns the new KPI.
private Kpi CreateFixedValueKPI(string kpiName, string listUrl)
{
    if (String.IsNullOrEmpty(kpiName))
        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.");

    Kpi newKpi = Kpi.CreateNew();
    newKpi.Name.Text = kpiName;
    newKpi.Description.Text = "Created with the SDK.";

    // Create a fixed value actual and set the value to 80.
    newKpi.Actual.DataSourceLocation = new RepositoryLocation(Constants.FixedValuesDataSourceLocationKey);
    newKpi.Actual.ModelCurrent = 80; 

    // Create a fixed value target and set the value to 100.
    Target target1 = new Target();
    target1.Guid = Guid.NewGuid();
    target1.Name.Text = "Target";
    target1.DataSourceLocation = newKpi.Actual.DataSourceLocation;
    target1.ModelCurrent = 100;
    target1.IndicatorLocation =
        BuiltinIndicators.GetIndicatorByCode(BuiltinIndicators.IndicatorCode.ShapesJagged3Small).Location;
    target1.Pattern = KpiPattern.IncreasingIsBetter;
    target1.RelatedActualId = newKpi.Actual.Guid;

    // Set up the banding for three bands:  < .5; .5 - 1.0; > 1.0.
    target1.Banding.ActualWorst = 0;
    target1.Banding.Type = BandType.Normalized;
    target1.Banding.SpreadMaximum = 1.2M;
    target1.Banding.SpreadMinimum = 0;
    target1.Banding.CustomBoundary.Add(.50M);
    target1.Banding.CustomBoundary.Add(1M);
    newKpi.Targets.Add(target1);

    // Call the CreateKpi method to save the new KPI to the specified list.
    // TODO: Handle exceptions from this call.
    return SPDataStore.GlobalDataStore.CreateKpi(listUrl, newKpi);
}
// Create a KPI that uses an Analysis Services data source, based on the following parameters:
//   - kpiName is the name for the KPI.
//   - listUrl is the server-relative URL of the list to save the KPI to. Example: 
//         "/BI Center/Lists/PerformancePoint Content"
//   - dataSource is the data source to use for the actual and target values.
// This method returns the new KPI.
private Kpi CreateKpiWithDatasource(string kpiName, string listUrl, DataSource dataSource)
{
    if (String.IsNullOrEmpty(kpiName))
        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 == dataSource)
        throw new ArgumentNullException("dataSource");

    Kpi newKpi = Kpi.CreateNew();
    newKpi.Name.Text = kpiName;
    newKpi.Description.Text = "Analysis Services KPI created with the SDK.";
    newKpi.Actual.DataSourceLocation = dataSource.Location;

    // Set the "actual" measure.
    DefaultDimensionSetting actualMeasureSettings = new DefaultDimensionSetting
                                                  {
                                                      DisplayName = "Measures",
                                                      UniqueName = "[Measures]",
                                                      IsMeasureDimension = true
                                                  };
    Member actualMeasure = new Member("[Measures].[Internet Gross Profit]")
                         {
                             Caption = "Internet Gross Profit",
                             DimensionName = "Measures.Measures",
                             DimensionUniqueName = "[Measures]",
                             MemberType = MemberType.Formula
                         };
    actualMeasureSettings.Members.Add(actualMeasure);
    newKpi.Actual.DefaultDimensionSettings.Add(actualMeasureSettings);

    // Add a dimension filter for the actual and set it to the year 2004.
    DefaultDimensionSetting actualFilterYear = new DefaultDimensionSetting
    {
        DisplayName = "Date.Date.Calendar",
        UniqueName = "[Date].[Calendar]",
        IsMeasureDimension = false
    };
    Member year2004 = new Member("[Date].[Calendar].[Calendar Year].&[2004]")
    {
        Caption = "CY 2004",
        LevelName = "[Date].[Calendar].[Calendar Year]",
        DimensionName = "Date.Date.Calendar",
        LevelDepth = 1,
        IsAllLevel = false,
        DimensionUniqueName = "[Date].[Calendar]",
        MemberType = MemberType.Regular
    };
    actualFilterYear.Members.Add(year2004);
    newKpi.Actual.DefaultDimensionSettings.Add(actualFilterYear);

    // Create the target.
    Target target1 = new Target();
    target1.Guid = Guid.NewGuid();
    target1.Name.Text = "Target";
    target1.IndicatorLocation =
        BuiltinIndicators.GetIndicatorByCode(BuiltinIndicators.IndicatorCode.SmileyA3Small).Location;
    target1.Pattern = KpiPattern.IncreasingIsBetter;
    target1.RelatedActualId = newKpi.Actual.Guid;

    // Set up the banding for three bands:  < .5; .5 - 1.0; > 1.0
    target1.Banding.ActualWorst = 0;
    target1.Banding.Type = BandType.Normalized;
    target1.Banding.SpreadMaximum = 1.2M;
    target1.Banding.SpreadMinimum = 0;
    target1.Banding.CustomBoundary.Add(.50M);
    target1.Banding.CustomBoundary.Add(1M);
    target1.DataSourceLocation = dataSource.Location;

    // Set the target. Use a custom formula to set the target at 10% growth from 2003.
    target1.IsCustomCurrentFormula = true;
    target1.CurrentFormula =
        "([Measures].[Internet Gross Profit], [Date].[Calendar].[Calendar Year].&[2003]) * 1.1";
    newKpi.Targets.Add(target1);

    // Call the CreateKpi method to save the new KPI to the specified list.
    // TODO: Handle exceptions from this call.
    return SPDataStore.GlobalDataStore.CreateKpi(listUrl, newKpi);
}

Voir aussi

Référence

SPDataStore classe

SPDataStore - Membres

Microsoft.PerformancePoint.Scorecards.Store - Espace de noms