Business Central provides you the feature to export the data in Excel in General Ledger entries, Customer Ledger entries, etc. But we can export data in a text file. In this blog, we will see how we can export data in the form of a text file.
Steps to achieve the goal:
- Create a codeunit that will export the data in text.
- We will be needing Temp Blob Codeunit, Instream, and OutStream to read and write the data in the file.
- Below is the code which will read and write the data in the text file.
- You can use dynamic filename also by assigning a field value in the FileName variable;
- FileName: Rec_ComapanyInformation.FileNameText // FileNameText is the field present in the Company Information Page which will be used as Filename of the exported text file.
- We will be also using an action that will call the Codeunit function (GenerateTextFile)
- The output of the above code is
- To avoid using multiple times Write Text function if there is a lot of data that needs to be pulled from multiple fields. You can use a variable and store all the values in that variable and then assign that variable in the WriteText function.
9. The output of the above code is
Thus we saw how we can export data from Business Central in a text file.
Thank you very much for reading my work. Hope you enjoyed the article!