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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Export CSV file using Class

(0) ShareShare
ReportReport
Posted on by 60

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

I have the same question (0)
  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    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]

  • Vilmos Kintera Profile Picture
    46,149 on at

    Sukrut, he is talking about the other way around - how to generate a CSV file and transport it for third parties as an export.

  • AX Ankit Profile Picture
    60 on at

    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.

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    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?

  • DimanC Profile Picture
    113 on at

    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?

  • Vilmos Kintera Profile Picture
    46,149 on at

    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.

  • Suggested answer
    Fedir Kryvyi Profile Picture
    1,026 on at

    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.

  • AX Ankit Profile Picture
    60 on at

    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.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans