ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Desktop.Reports Namespace / ReportTemplateManager Class / GetCustomTemplateDefinition Method
The name of the custom report template.
Example

In This Topic
    GetCustomTemplateDefinition Method
    In This Topic
    Gets the definition of a custom template to be populated and used to create a report. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public static ReportCustomTemplateDefinition GetCustomTemplateDefinition( 
       string templateName
    )
    Public Shared Function GetCustomTemplateDefinition( _
       ByVal templateName As String _
    ) As ReportCustomTemplateDefinition

    Parameters

    templateName
    The name of the custom report template.

    Return Value

    The template definition.
    Exceptions
    ExceptionDescription
    The templateName does not exist.
    Example
    Create a report from a custom report template
    {
      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 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.6 or higher.
    See Also