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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to convert records to CSV format?

(0) ShareShare
ReportReport
Posted on by 465

When i'm standing at a customer record i want to take these values and convert them to csv format then use info() to see the format. How can i do that?

I have the same question (0)
  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    Hi,

    There is a global method buf2con which converts record to a container. The container can be converted to a comma-separated string with method con2str or con2strUnlimited.

    con2StrUnlimited(buf2con(custTable), ";");

  • qianwang Profile Picture
    7,168 on at

    Hi D365FO user,

    Please try this:

    Query q;

    QueryBuildDataSource qbds;

    QueryBuildRange qbr;

    QueryRun qr;

    CustTable custTable;

    q = new Query();

    qbds = q.addDataSource(tablenum(CustTable ));

    qbr = qbds.addRange(fieldnum(CustTable,ItemId)); //Range

    qr = new QueryRun(q);

    while( qr.next() )

    {

    custTable= qr.get(tablenum(CustTable));

    info(custTable.name(),custTable.AccountNum);

    }

    Hope this helps.

    Regards,

    QianQW

  • D365FO user Profile Picture
    465 on at

    If i want a general class to take any query and convert it CSV format then print the format how can i do that?

  • Sukrut Parab Profile Picture
    71,710 Moderator on at

    Whats the definition of general class here ? and  what is business requirement behind this ?

  • D365FO user Profile Picture
    465 on at

    Hi Sukrut,

    The business requirment is when you want to call an api by code to send data( whatever the data is wether it's the whole table fields or few fields) you should be able to convert the data to csv, xml or json.

    I wanted to start with csv first.

    I don't know what is the right approach is it query or string or data entities (but data entities i think they are only for import or export)

    Please advise

  • Suggested answer
    Sukrut Parab Profile Picture
    71,710 Moderator on at

    You can use data entities,. data entities support csv format.  Did you look at data management package API ?  Take a loo at below link. You can create data entity for a table which you want to export and use data package API which will give you csv  format.

    docs.microsoft.com/.../data-management-api

  • D365FO user Profile Picture
    465 on at

    Hi sukrut,

    Would this work for xml and json as well?

    And can this be done by code? I mean i already did the code to call the api where i get the access token first then i send the data. What i want is instead of sending normal txt data i want to send data in another format so i have to do something to convert it to the required format and then replace my code with the normal txt to the required format.

  • qianwang Profile Picture
    7,168 on at

    Hi D365FO user,

    This is not a simple question. Although it is simple to output tables in the format you want, it is difficult to achieve high versatility.

    You can think about other way to integrate, try to use BYOD, and you can do more data manipulation on your own data warehouse

    Refer to the DOC:

    docs.microsoft.com/.../export-entities-to-your-own-database

    Regards,

    QianQW

  • D365FO user Profile Picture
    465 on at

    Hi Qian,

    i don't think BYOD is what i need.

    As i mentioned before i want to send data from D365FO to another server.

    I made a code where i call the API (first i get the authentication then i send the data).

    Now in the method SendData, i prepare the header,request,body and response.

    Now in preparing the body i do the following:

    System.IO.Stream bodyStream;

       public void Body(System.Net.WebRequest request, str body)

       {

           System.Byte[] byteArray  = encoding.GetBytes(body);

           request.set_ContentLength(byteArray.get_Length());

           bodyStream= request.GetRequestStream();

           bodyStream.Write(byteArray, 0, byteArray.get_Length());

       }

    Now as you can see the body here is string. So before calling the method body, i want to prepare my data to be in CSV,JSON or XML format.

    So for example let's say i want to send the customerName and customerAccount, then i have to take this data and convert it to XML then take this data and send it to the body method. (i don't want the file i want the data format in string)

    My question is how to convert it to XML or other formats. I read that in 2012 there was something that serialize query to XML in AIF.

    So how should i send the data? should i send it as query then serialze the query to xml or csv or json? is this doable if yes how?

  • Suggested answer
    Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at

    What do you mean by "send as query"? First of all, you mean data, not a query, and the function accepts a string, not objects. Therefore you must serialize the data to a string; you have no choice to make.

    Yes, AIF document services have the possibility to serialize AIF document classes to XML, but it's not really going to help you.

    Because your data can't containing hierarchies, the structure of files will be very simple. In this case, I would probably implement serialization by myself. I would create three serializer classes implementing a common interface, and a sender class accepting the data and a serializer (the interface).

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans