Compartir a través de


Publicar un informe mediante el servicio web de Microsoft Dynamics 365

 

Publicado: enero de 2017

Se aplica a: Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online

Para publicar un informe en Microsoft Dynamics 365, puede crear un nuevo registro del informe o actualizar un registro de informe existente. Use el método IOrganizationService.Create para crear un informe, o use el método IOrganizationService.Update para actualizar un informe. Debe especificar el tipo de informe, su visibilidad, su categoría y las entidades relacionadas para el informe, como se muestra a continuación.

Especifique el tipo de informe

Cuando cree un registro de informe, especifique el tipo de informe mediante el atributo Report.ReportTypeCode. Un informe puede ser de uno de los tipos siguientes:

  • Informe de Reporting Services: para este tipo de informe, establezca el valor del atributo Report.BodyText. Además, especifique el nombre del archivo .rdl que contiene la definición del informe mediante el atributo Report.Filename.

  • Otro informe: para este tipo de informe, establezca el valor del atributo Report.BodyBinary. Especifique el nombre del archivo .rdl que contiene la definición del informe mediante el atributo Report.Filename.

  • Informe vinculado: para este tipo de informe, establezca el valor del atributo Report.BodyUrl.

Especifique la categoría del informe

Para mostrar y ejecutar un informe de las distintas categorías de informe, como Marketing, Ventas, o Servicio, use el atributo ReportCategory.CategoryCode para especificar una categoría. Puede especificar varias categorías para un informe.

Especifique la visibilidad del informe

De forma predeterminada, el informe se puede ver en la vista Todos los informes, incluidos los subinformes de la cuadrícula Informes. Para mostrar un informe en otras vistas de la cuadrícula, o distintas áreas, como el formulario de entidad o la cuadrícula de entidad, use el atributo ReportVisibility.VisibilityCode para especificar la vista o el área. Puede especificar varias vistas y áreas para un informe.

Especifique las entidades del informe

Para especificar una entidad relacionada para el informe, use el atributo ReportEntity.ObjectTypeCode. Puede especificar varias entidades relacionadas.

Ejemplo

Este ejemplo muestra cómo crear los registros necesarios para publicar un informe.



// 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)

Ver también

Guía para programadores sobre informes de Microsoft Dynamics 365
Publicación de informes
Ejemplo: publicar un informe
Administre un informe en modo sin conexión

Microsoft Dynamics 365

© 2017 Microsoft. Todos los derechos reservados. Copyright