Notifications
Announcements
No record found.
Hello,
I am trying to export customer data in a CSV file in Dynamics 365 for operations. Can anyone provide a sample code or reference to do this?
*This post is locked for comments
It has been changed considerably since D365fF&O is a cloud solution, so you must forget the traditional file handling, since now everything happens server-side for which you do not have direct access.
Refer to this thread for dealing with files in:
[View:https://community.dynamics.com/ax/f/33/t/231121:750:50]
You should consider Recurring integrations for this:
[View:https://docs.microsoft.com/en-us/dynamics365/unified-operations/dev-itpro/data-entities/recurring-integrations:750:50]
Sukrut, he is talking about the other way around - how to generate a CSV file and transport it for third parties as an export.
Yes that's right. I was checking the links you have indicated. I found the below code in one of those links:
class fileInteractionTest
{
public static void main(Args _args)
FileUploadTemporaryStorageResult result;
result = File::GetFileFromUser(classStr(FileUploadTemporaryStorageStrategy));</pre>
if(result && result.getUploadStatus())
Info(result.getDownloadUrl());
new Browser().navigate(result.getDownloadUrl());
}
This code gets file from user and then downloads it. But how to generate file from data within D365 f&O and then download it.
Your request can be fulfilled with a recurring data job linked above which is exactly to generate output files from D365fF&O data in a repeatable manner, did you check it?
Hi Vilmos
I'm facing the the same challenge as author of this topic. Thank you for good links and suggestions
May I ask you how using Recurring integrations can satisfy the original requirement? In my understanding, when someone develops class for export (like in good old days...), the aim is to write to file "on demand" (sync operation), and using custom filters.
"Recurring integrations" using data managment is typical Async operation, running in background. Or is there any way how to get an immediate / on-demand response from that module?
Regarding filtering - filters can be set in UI for the relevant Export job. Can these filters also be adjusted by code / in run-time?
To be precise the recurring integrations is to be used in case you want a repeatable way of pulling information from your source system (D365) and provide it for third parties, by accessing your environment through a web URL.
The output format is not a CSV document though (as opposed to the original request) since it is hard to represent a complex data structure in a flat file, but a zipped file collection of the entities involved.
You could initiate this pull with the "dequeue" RESTful API from the customer end for an already published endpoint.
I am unaware if filters could be manipulated programmatically or not.
Any CSV file is basically a txt file with appropriate formatting.
1. Create new instance of System.IO.MemoryStream
2. Create new instance of System.IO.StreamWriter using your System.IO.MemoryStream
3. Write formatted data using strFmt to StreamWriter
4. Use your MemoryStream and File class to send file to user.(There is method for that in AX)
Basically any C# tutorial would work, the only difference is that you don't have filepath, but instead you are using Stream + AX class to send file to user.
Another option would be to store generate CSV inside AX and attach it to record, for that you will need to use DocumentManagement framework.
Hope that helps.
Hi Fedir,
Thanks for your input. I am relatively new to D365 for operations. It will be really helpful if you can provide me with a simple sample code.
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Priya_K 4
Martin Dráb 4 Most Valuable Professional
Ali Zaidi 2