D365/AX:Export or download records into CSV file or format from D365 Finance & Operations Environment using X++

Requirement

Export or download records into CSV file or format from D365 Finance & Operations Environment using X++ Code.

Sample Code

[code language=”cpp”]

class ACXExportCSV
{
public void export()
{
CommaStreamIo commaStreamIo = CommaStreamIo::constructForWrite();
InventTable inventTable;
InventSum inventSum;

;

const str fileName = ‘Export.csv’;
commaStreamIo.writeExp([‘Item Code’, ‘Item Name’, ‘Available Physical’]);
while select * from inventTable
{
select sum(AvailPhysical) from inventSum
where inventSum.ItemId == inventTable.ItemId;
commaStreamIo.writeExp([strFmt(‘%1’, inventTable.ItemId), strFmt(‘%1’, inventTable.itemName()), strFmt(‘%1’, inventSum.AvailPhysical)]);
}
System.IO.Stream stream = commaStreamIo.getStream();
stream.Position = 0;

FileUploadTemporaryStorageResult result = File::SendFileToTempStore_GetResult(stream, fileName);
info(result.getDownloadUrl());
Message::Add(MessageSeverity::Informational, result.getDownloadUrl());

}

}

[/code]

Cheers 🙂

Piyush Adhikari

 

 

Leave a Reply