IAnalyticReporting.GetDataSource (List<FieldForQdvFldConfigFile>, Boolean, String, Boolean, Boolean, Boolean) Method

Gets a data-source workbook from a list of fields / worksheets.
IWorkbook GetDataSource( 
   bool groupsAreCollapsed
   string headBranchIdentifier = "001000000000000000000000"
   bool displayProgressWindows = False, 
   bool includeOverheadMinute = False, 
   bool includeDatabaseOfEstimate = False 
)

Parameters

fields
List<FieldForQdvFldConfigFile>

A list of FieldForQdvFldConfigFile which can be created programmatically or retrieved using the GetImageOfFieldsForDataSource function.

groupsAreCollapsed
bool

A value indicating whether the data source should have collapsed groups.

headBranchIdentifier
string

The task/branch for which to get the data. An empty string or '001000000000000000000000' means entire WBS tree.

displayProgressWindows
bool

When true, QDV will display a progress window in the center of the screen.

includeOverheadMinute
bool

A value indicating whether the data source must contain the lines of the overhead minute if any.

includeDatabaseOfEstimate
bool

A value indicating whether the data source must contain the lines of the database of estimate if any.

Return Value

IWorkbook

A workbook containing all data of the data-source.

Remarks
 

Not all WBS and minutes fields can have their FieldForQdvFldConfigFile.UseEightLevels set to true. WBS sum fields cannot apply, and only KindID and list minutes fields apply. If any WBS or minutes field in fields breaks this rule, no error is reported, but its FieldForQdvFldConfigFile.UseEightLevels property is ignored.

For historical reasons and for backward compatibility with old macros, this methods doesn't throw exceptions when an error is encountered. Instead, it sets a global error message. This allows to report just one (first) error. These global error messages are automatically displayed by QDV after a macro has finished.

You can read this error info programmatically. You can get it from IQdvEnvironment.GlobalErrors property. In macros, it's accessible from the Context parameter:

 Context.QdvManager.Environment.GlobalErrors
 					
Example
 
IAnalyticReporting aTools = es.CurrentVersion.GetAnalyticReportingTools();
 // Get all available fields for data source and where applicable, set their "All levels" to True.
 IEnumerable<FieldForQdvFldConfigFile> fields = aTools.GetAvailableFieldsForDataSource(useEightLevelsWhereApplicable: true);
 // Now you can customize or remove individual fields, if needed.
  
 // Save the fields configuration into a qdvfldconfig file. This is an optional step.
 bool collapsed = true;
 aTools.SaveFieldsForDataSource(@"C:\test.qdvfldconfig", fields, collapsed);
  
 // Create the data source.
 IWorkbook dataSourceWorkbook = aTools.GetDataSource(new List<FieldForQdvFldConfigFile>(fields), collapsed);
  
 // Check the errors, because GetDataSource doesn't throw exceptions.
 if (dataSourceWorkbook == null)
 {
     // An error occurred, get the details.
     if (!String.IsNullOrEmpty(context.QdvManager.Environment.GlobalErrors.GlobalErrorMessage))
     {
         // The error is reported in GlobalErrorMessage.
         string errText = context.QdvManager.Environment.GlobalErrors.GlobalErrorMessage;
         MessageBox.Show(errText, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else if (context.QdvManager.Environment.GlobalErrors.MessageStack.Count > 0)
     {
         // The error(s) is/are reported in MessageStack, display them all.
         string errText = "";
         foreach (string err in context.QdvManager.Environment.GlobalErrors.MessageStack)
         {
             errText += err + "\n";
         }
         MessageBox.Show(errText, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     else
     {
         // No error details.
     }
 }                   

The following example shows, how to correctly handle errors from GetDataSource method which uses the old error handling.

Version
 
Available since QDV 7.23.1069.

.NET Framework

Supported in: 4.8, 4.7, 4.6, 4.5.2