使用 Microsoft Dynamics 365 Web 服务发布报表

 

发布日期: 2017年1月

适用于: Dynamics 365 (online),Dynamics 365 (on-premises),Dynamics CRM 2016,Dynamics CRM Online

若要将报表发布到 Microsoft Dynamics 365,您可以创建新的报表记录或者更新现有报表记录。 使用 IOrganizationService.Create 方法可创建报表,使用 IOrganizationService.Update 方法可更新报表。 必须指定报表类型、报表可见性、报表类别和报表的相关实体,如下所示。

指定报表类型

创建报表记录时,可使用 Report.ReportTypeCode 属性指定报表类型。 报表可以为以下类型之一:

  • Reporting Services 报表:对于此报表类型,设置 Report.BodyText 属性的值。 还要使用 Report.Filename 属性指定包含报表定义的 .rdl 文件的名称。

  • 其他报表:对于此报表类型,设置 Report.BodyBinary 属性的值。 使用 Report.Filename 属性可指定包含报表定义的 .rdl 文件的名称。

  • 链接报表:对于此报表类型,设置 Report.BodyUrl 属性的值。

指定报表类别

若要在不同的报表类别(如“市场营销”“销售”或“服务”)中显示并运行报表,请使用 ReportCategory.CategoryCode 属性指定类别。 可为一个报表指定多个类别。

指定报表可见性

默认情况下,报表显示在“报表”网格的“所有报表,包括子报表”视图中。 若要在该网格的其他视图或者不同区域(实体窗体或实体网格)中显示报表,请使用 ReportVisibility.VisibilityCode 属性指定视图或区域。 可为一个报表指定多个视图和区域。

指定报表实体

若要为报表指定相关实体,请使用 ReportEntity.ObjectTypeCode 属性。 您可以指定多个相关实体。

示例

此示例演示如何创建发布报表所需的记录。



// Define an anonymous type to define the possible values for
// report type.
var ReportTypeCode = new
{
    ReportingServicesReport = 1,
    OtherReport = 2,
    LinkedReport = 3
};

// Define an anonymous type to define the possible values for
// report category.
var ReportCategoryCode = new
{
    SalesReports = 1,
    ServiceReports = 2,
    MarketingReports = 3,
    AdministrativeReports = 4
};

// Define an anonymous type to define the possible values for
// report visibility
var ReportVisibilityCode = new
{
    ReportsGrid = 1,
    Form = 2,
    Grid = 3,
};

// Instantiate a report object.
// See the Entity Metadata topic in the SDK documentation to determine
// which attributes must be set for each entity.

Report sampleReport = new Report
{
    Name = "Sample Report",
    BodyText = File.ReadAllText("SampleReport.rdl"),
    FileName = "SampleReport.rdl",
    LanguageCode = 1033, // US English
    ReportTypeCode = new OptionSetValue(ReportTypeCode.ReportingServicesReport)
};
// Create a report record named Sample Report.
_reportId = _serviceProxy.Create(sampleReport);


// Set the report category.
ReportCategory sampleReportCategory = new ReportCategory
{
    ReportId = new EntityReference(Report.EntityLogicalName, _reportId),
    CategoryCode = new OptionSetValue(ReportCategoryCode.AdministrativeReports)
};
_reportCategoryId = _serviceProxy.Create(sampleReportCategory);

// Define which entity this report uses.
ReportEntity reportEntity = new ReportEntity
{
    ReportId = new EntityReference(Report.EntityLogicalName, _reportId),
    ObjectTypeCode = Account.EntityLogicalName
};
_reportEntityId = _serviceProxy.Create(reportEntity);


// Set the report visibility.
ReportVisibility rv = new ReportVisibility
{
    ReportId = new EntityReference(Report.EntityLogicalName, _reportId),
    VisibilityCode = new OptionSetValue(ReportVisibilityCode.Form)
};
_reportVisibilityId1 = _serviceProxy.Create(rv);

rv = new ReportVisibility
{
    ReportId = new EntityReference(Report.EntityLogicalName, _reportId),
    VisibilityCode = new OptionSetValue(ReportVisibilityCode.Grid)
};
_reportVisibilityId2 = _serviceProxy.Create(rv);

rv = new ReportVisibility
{
    ReportId = new EntityReference(Report.EntityLogicalName, _reportId),
    VisibilityCode = new OptionSetValue(ReportVisibilityCode.ReportsGrid)
};
_reportVisibilityId3 = _serviceProxy.Create(rv);

Console.WriteLine("{0} published in Microsoft Dynamics CRM.", sampleReport.Name);


' Define an anonymous type to define the possible values for
' report type.
Dim ReportTypeCode = New With {
     Key .ReportingServicesReport = 1,
     Key .OtherReport = 2,
     Key .LinkedReport = 3}

' Define an anonymous type to define the possible values for
' report category.
Dim ReportCategoryCode = New With {
     Key .SalesReports = 1,
     Key .ServiceReports = 2,
     Key .MarketingReports = 3,
     Key .AdministrativeReports = 4}

' Define an anonymous type to define the possible values for
' report visibility
Dim ReportVisibilityCode = New With {
     Key .ReportsGrid = 1,
     Key .Form = 2,
     Key .Grid = 3}

' Instantiate a report object.
' See the Entity Metadata topic in the SDK documentation to determine
' which attributes must be set for each entity.

Dim sampleReport As Report =
 New Report With {
  .Name = "Sample Report",
  .BodyText = File.ReadAllText("SampleReport.rdl"),
  .FileName = "SampleReport.rdl",
  .LanguageCode = 1033,
  .ReportTypeCode = New OptionSetValue(ReportTypeCode.ReportingServicesReport)
 }
' Create a report record named Sample Report.
_reportId = _serviceProxy.Create(sampleReport)


' Set the report category.
Dim sampleReportCategory As ReportCategory =
 New ReportCategory With {
  .ReportId = New EntityReference(Report.EntityLogicalName, _reportId),
  .CategoryCode = New OptionSetValue(ReportCategoryCode.AdministrativeReports)
 }
_reportCategoryId = _serviceProxy.Create(sampleReportCategory)

' Define which entity this report uses.
Dim reportEntity As ReportEntity =
 New ReportEntity With {
  .ReportId = New EntityReference(Report.EntityLogicalName, _reportId),
  .ObjectTypeCode = Account.EntityLogicalName
 }
_reportEntityId = _serviceProxy.Create(reportEntity)


' Set the report visibility.
Dim rv As ReportVisibility =
 New ReportVisibility With {
  .ReportId = New EntityReference(Report.EntityLogicalName, _reportId),
  .VisibilityCode = New OptionSetValue(ReportVisibilityCode.Form)
 }
_reportVisibilityId1 = _serviceProxy.Create(rv)

rv = New ReportVisibility With {
 .ReportId = New EntityReference(Report.EntityLogicalName, _reportId),
 .VisibilityCode = New OptionSetValue(ReportVisibilityCode.Grid)
}
_reportVisibilityId2 = _serviceProxy.Create(rv)

rv = New ReportVisibility With {
 .ReportId = New EntityReference(Report.EntityLogicalName, _reportId),
 .VisibilityCode = New OptionSetValue(ReportVisibilityCode.ReportsGrid)
}
_reportVisibilityId3 = _serviceProxy.Create(rv)

Console.WriteLine("{0} published in Microsoft Dynamics CRM.", sampleReport.Name)

另请参阅

针对 Microsoft Dynamics 365 报表的开发人员指南
发布报表
示例:发布报表
在脱机模式下管理报表

Microsoft Dynamics 365

© 2017 Microsoft。 保留所有权利。 版权