IAdhocReport.AddNewDataSourceObject

Fore Syntax

AddNewDataSourceObject(Id: String; CreateInfo: IMetabaseObjectCreateInfo): IAdhocDataSourceObject;

Fore.NET Syntax

AddNewDataSourceObject(Id: string; CreateInfo: Prognoz.Platform.Interop.Metabase.IMetabaseObjectCreateInfo): Prognoz.Platform.Interop.AdHoct.IAdhocDataSourceObject;

Parameters

Id. Dashboard object identifier.

CreateInfo. An object containing parameters of created object.

Description

The AddNewDataSourceObject method creates and adds a data source.

Comments

To copy the specified data source, use the IAdhocReport.CopyDataSourceObject method.

Fore Example

Executing the example requires that the repository contains a dashboard with the DASHBOARD_ANDSO identifier.

Add links to the Adhoc, Metabase system assemblies.

Sub UserProc;
Var
    mb: IMetabase;
    Dashboard: IAdhocReport;
    DsObjs: IAdhocDataSourceObjects;
    i: Integer;
    DsObj: IAdhocDataSourceObject;
    mbo: IMetabaseObject;
    mboci: IMetabaseObjectCreateInfo;
Begin
    // Get current repository
    mb := MetabaseClass.Active;
    // Get dashboard
    mbo := mb.ItemById("DASHBOARD_ANDSO").Edit;
    Dashboard := mbo As IAdhocReport;
    // Get dashboard data sources
    DsObjs := Dashboard.DataSourceObjects;
    DsObjs.RemoveById("NewER");
    //Add a new data source
    mboci := mb.CreateCreateInfo;
    mboci.ClassID := MetabaseObjectClass.KE_CLASS_EXPRESSREPORT;
    mboci.Id := "NewER";
    mboci.Name := "NewER";
    mboci.Parent := mb.ItemById("DASHBOARD_ANDSO");
    DsObj := Dashboard.AddNewDataSourceObject("NewER", mboci);
    For i := 0 To DsObjs.Count - 1 Do
        // Get data source name
        DsObj := DsObjs.Item(i);
        Debug.WriteLine("Data source name " + (i + 1).ToString + " - " + DsObj.SourceObjectDescriptor.Name);
        // Get data source identifier
        Debug.WriteLine("Data source identifier " + (i + 1).ToString + " - " + DsObj.Id);
    End For;
End Sub UserProc;

After executing the example a new data source with the NewER identifier is added to the dashboard, the console window displays names and identifiers of data sources.

Fore.NET Example

The requirements and result of the Fore.NET example execution match with those in the Fore example.

Imports Prognoz.Platform.Interop.Adhoc;

Public Shared Sub Main(Params: StartParams);
Var
    mb: IMetabase;
    Dashboard: IAdhocReport;
    DsObjs: IAdhocDataSourceObjects;
    i: Integer;
    DsObj: IAdhocDataSourceObject;
    mbo: IMetabaseObject;
    mboci: IMetabaseObjectCreateInfo;
Begin
    // Get current repository
    mb := Params.Metabase;
    // Get dashboard
    mbo := mb.ItemById["DASHBOARD_ANDSO"].Edit();
    Dashboard := mbo As IAdhocReport;
    // Get dashboard data sources
    DsObjs := Dashboard.DataSourceObjects;
    DsObjs.RemoveById("NewER");
    //Add a new data source
    mboci := mb.CreateCreateInfo();
    mboci.ClassID := MetabaseObjectClass.KE_CLASS_EXPRESSREPORT As Int32;
    mboci.Id := "NewER";
    mboci.Name := "NewER";
    mboci.Parent := mb.ItemById["DASHBOARD_ANDSO"];
    DsObj := Dashboard.AddNewDataSourceObject("NewER", mboci);
    For i := 0 To DsObjs.Count - 1 Do
        // Get data source name
        DsObj := DsObjs.Item[i];
        System.Diagnostics.Debug.WriteLine("data source name " + (i + 1).ToString() + " - " + DsObj.SourceObjectDescriptor.Name);
        // Get data source identifier
        System.Diagnostics.Debug.WriteLine("data source identifier " + (i + 1).ToString() + " - " + DsObj.Id);
    End For;
End Sub;

See also:

IAdhocReport