ArcGIS Pro 3.6 API Reference Guide
ArcGIS.Desktop.Reports Namespace / ReportCustomTemplateDataSourceInfo Class / SetReportDataSource Method / SetReportDataSource(MapMember) Method
MapMember object defining data source for the report.
Example

In This Topic
    SetReportDataSource(MapMember) Method
    In This Topic
    Sets the report data source map member.
    Syntax
    public void SetReportDataSource( 
       MapMember mapMember
    )
    Public Overloads Sub SetReportDataSource( _
       ByVal mapMember As MapMember _
    ) 

    Parameters

    mapMember
    MapMember object defining data source for the report.
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    mapMember
    MapMember is not a valid report data source.
    Example
    Create a report from a custom report template
    //Note: Run within QueuedTask.Run()
    await QueuedTask.Run(() =>
    {          
      // get the first map in the project
      MapProjectItem item = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(n => n.Name == "Cities");
      if (item == null)
        return;
    
      Map map = item.GetMap();
      if (map == null)
        return;
    
      Layer cityLayer = map.FindLayers("U.S. Cities")[0];
      if (cityLayer == null)
        return;
    
      // load template information
      var templatePath = System.IO.Path.Combine($@"{Project.Current.HomeFolderPath}\TemplateSimpleReportWithTokens.rptt");
      ReportCustomTemplateDefinition templateDef = ReportTemplateManager.GetCustomTemplateDefinition(templatePath);
      if (templateDef == null || templateDef.ReportTemplateDataSourceItems?.Count() < 1)
        return;
    
      // get template info of first data source (parent) and set its data source
      ReportCustomTemplateDataSourceInfo parentDataSourceInfo = templateDef.ReportTemplateDataSourceItems.ElementAt(0);
    
      parentDataSourceInfo.SetReportDataSource(cityLayer);
    
      TemplateTokenFieldInfoValues templateTokenFieldInfoValues = parentDataSourceInfo.TokenInfoValues;
    
      parentDataSourceInfo.DefinitionQuery = "STATE_NAME = 'Massachusetts'";
      templateTokenFieldInfoValues["[text-field-value-0]"] = "CITY_NAME";
      templateTokenFieldInfoValues["[text-field-name-0]"] = "City";
      templateTokenFieldInfoValues["[numeric-field-value-0]"] = "POP1990";
      templateTokenFieldInfoValues["[numeric-field-name-0]"] = "Population";
    
      if (templateDef.CanCreateReport())
      {
        // create the report
        report = ReportFactory.Instance.CreateReport("RelateSiblingsFromCode", templateDef);
      }
    });
    //UI thread
    if (report != null)
    {
      //open report
      await FrameworkApplication.Panes.CreateReportPaneAsync(report);
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.6 or higher.
    See Also