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 属性を使用してカテゴリを指定します。 1 つのレポートに対して複数のカテゴリを指定することができます。

レポート表示領域の指定

既定では、レポートは [レポート] グリッドの [すべてのレポート (サブレポートを含む)] ビューに表示されます。 グリッドの追加のビュー、またはエンティティ フォームやエンティティ グリッドなどの別の領域にレポートを表示するには、ReportVisibility.VisibilityCode 属性を使用してビューまたは領域を指定します。 1 つのレポートに対して複数のビューや領域を指定することができます。

レポート エンティティの指定

レポートの関連エンティティを指定するには、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. All rights reserved. 著作権