Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

Can I extract custom reports from business central as pdf through an API?

(0) ShareShare
ReportReport
Posted on by 57

I am trying to extract some reports i have created through an external API but i can't seem to find a way how to.

Any assistance would be appreciated

  • Suggested answer
    Bilal Haider Profile Picture
    Bilal Haider 47 on at
    RE: Can I extract custom reports from business central as pdf through an API?

    Yes you can. One way can be similar to this code.

    procedure ExportReport() responseText: Text

       var

           ResponseObject: JsonObject;

       begin

           ResponseObject.Add('reportName', 'Inventory List');

           ResponseObject.Add('extension', 'xlsx');

           ResponseObject.Add('content', RunReport());

           ResponseObject.WriteTo(responseText);

       end;

       local procedure RunReport(): Text

       var

           InventoryListReport: Report "Inventory - List";

           TempBlob: Codeunit "Temp Blob";

           Base64Convert: Codeunit "Base64 Convert";

           FileText: Text;

           MyOutStream: OutStream;

           MyInStream: InStream;

       begin

           //SetTableView and SetReqFilter if required

           TempBlob.CreateOutStream(MyOutStream);

           InventoryListReport.UseRequestPage(false);

           InventoryListReport.SaveAs('', ReportFormat::Excel, MyOutStream);

           TempBlob.CreateInStream(MyInStream);

           FileText := Base64Convert.ToBase64(MyInStream);

           exit(FileText);

       end;

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,391 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans