AddNewDataSourceObject(Id: String; CreateInfo: IMetabaseObjectCreateInfo): IAdhocDataSourceObject;
Id. Dashboard object identifier.
CreateInfo. An object containing parameters of created object.
The AddNewDataSourceObject method creates and adds a data source.
To copy the specified data source, use the IAdhocReport.CopyDataSourceObject method.
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.
See also: