web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Business Central forum

How to export data into multiple files

(0) ShareShare
ReportReport
Posted on by 30

Hi Expert

I would like to know if it possible to generate multiple files in BC Cloud using XML port called from either Report or codeunit. 

The goal is to export sales invoice header information into CSV file, one file for each day.

In the previous version I can do this by creating an XML port to handle the export and code unit/Report to call supply the daily data to the XML Port

The code unit 

datefilter: Record Date;
FileInstream: InStream;
TempBlob: Record TempBlob;
FileName: Text;
MyOutStream: OutStream;
MyInStream: InStream;
outputFileName: Text;
MyXMLPort: XmlPort "My Export";

datefilter.SetRange("Period Type", datefilter."Period Type"::Date);
datefilter.SetRange("Period Start", 20190501D, 20190509D);
IF datefilter.FindSet then
REPEAT 

TempBlob.Blob.CreateOutStream(MyOutStream);

CLEAR(XMLPort);
MyXMLPort.SetFilter(datefilter."Period Start");  //SETFilterinXML Port
MyXMLPort.SetDestination(MyOutStream);
MyXMLPort.Run();

TempBlob.Blob.CreateInStream(MyInStream);
outputFileName := 'FileName' + '-' + FORMAT(dateFilter."Period Start", 0, '<Month,2><Day,2><Year4>') + '.txt';
DownloadFromStream(MyInStream, '', '', '', outputFileName)

UNTIL datefilter.Next = 0;

end;

When I run this in BC Cloud, I am only getting the file for the last date in my date range which is 20190509D

Categories:
  • Suresh Kulla Profile Picture
    50,280 Super User 2026 Season 1 on at

    This should not be any different, please check your date filters in the XMLPort.

  • Verified answer
    I Gusti Made Ari Profile Picture
    3,608 on at

    Yes, DownloadFromStream will only download the last file . The team know this issue and currently in their backlog. Workaround for this scenario is to archive the files in to ZIP.

    Please check below post on how to do that :

    github.com/.../3575

  • Suggested answer
    Carlos Yuwono Profile Picture
    30 on at

    Thank you! :)

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Business Central

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans