Partager via


Publier un rapport à l’aide du service Web Microsoft Dynamics 365

 

Date de publication : janvier 2017

S’applique à : Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online

Pour publier un rapport sur Microsoft Dynamics 365, vous pouvez créer un enregistrement de rapport ou mettre à jour un enregistrement de rapport existant. Utilisez la méthode IOrganizationService.Create pour créer un rapport ou la méthode IOrganizationService.Update pour mettre un rapport à jour. Spécifiez le type de rapport, sa visibilité, sa catégorie et les entités associées au rapport comme illustré ci-dessous.

Spécifiez le type de rapport.

Lorsque vous créez un enregistrement de rapport, spécifiez le type de rapport au moyen de l’attribut Report.ReportTypeCode. Un rapport peut avoir l’un des types suivants :

  • Rapport Reporting Services : pour ce type de rapport, définissez une valeur pour l’attribut Report.BodyText. En outre, indiquez le nom du fichier .rdl qui contient la définition du rapport à l’aide de l’attribut Report.Filename.

  • Autre rapport : pour ce type de rapport, définissez une valeur pour l’attribut Report.BodyBinary. Spécifiez le nom du fichier .rdl qui contient la définition du rapport à l’aide de l’attribut Report.Filename.

  • Rapport lié : pour ce type de rapport, définissez une valeur pour l’attribut Report.BodyUrl.

Spécifier la catégorie du rapport

Pour afficher et exécuter un rapport dans les différentes catégories de rapports, telles que Marketing, Ventes ou Service, utilisez l’attribut ReportCategory.CategoryCode pour spécifier une catégorie. Vous pouvez spécifier plusieurs catégories pour un rapport.

Spécifier la visibilité du rapport

Par défaut, le rapport est visible dans la vue Tous les rapports, y compris les sous-rapports de la grille Rapports. Pour sélectionner un rapport dans les vues supplémentaires de la grille, ou dans différentes zones, telles que le formulaire d’entité ou la grille d’entité, utilisez l’attribut ReportVisibility.VisibilityCode pour spécifier la vue ou la zone. Vous pouvez spécifier plusieurs vues et zones pour un rapport.

Spécifier les entités de rapport

Pour spécifier une entité associée pour le rapport, utilisez l’attribut ReportEntity.ObjectTypeCode. Vous pouvez spécifier plusieurs entités associées.

Exemple

Cet exemple montre comment créer les enregistrements nécessaires à la publication d’un rapport.



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

Voir aussi

Guide destiné aux développeurs chargés de la rédaction de rapports pour Microsoft Dynamics 365
Publier les rapports
Exemple : publier un rapport
Gérer un rapport en mode hors connexion

Microsoft Dynamics 365

© 2017 Microsoft. Tous droits réservés. Copyright