使用 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. 著作權所有,並保留一切權利。 著作權