Export Customers as a CSV file using Codeunit or Report

Hi All,

I want to export customers as a CSV file using Jobqueue.

Can you please provide me a piece of advice, whether i am creating code unit or report to run a jobqueue.

If it's possible through codeunit or report, please suggest me some piece of code to export a CSV file.

Thanks in advance,
Jacob.A

Best Answer

Answers

  • TallyHoTallyHo Posts: 282Member
    I hate to say.. ๐Ÿ˜
    Tomorrow you'll have an example. If no one beats me to it.
  • Sachin_Sachin_ Posts: 67Member
    Hello @Jacob1227 ,

    If you really want to use a report, you could use a "File" variable, but make sure you are not putting it on the server.

    OnPreDataItem()
    IF NOT FILE.EXISTS(<Your FileName>) THEN
    FILE.ERASE(<Your FileName>);

    fileExport.CREATE(<Your FileName>);
    fileExport.TEXTMODE := TRUE;
    fileExport.WRITEMODE := TRUE;

    OnAfterGetRecord()
    fileExport.WRITE(STRSUBSTNO('%1;%2;%3;%4;..",
    <Your Values>);

    OnPostDataItem()
    fileExport.CLOSE;
  • TallyHoTallyHo Posts: 282Member
    Remove file only when it exists.
  • Miklos_HollenderMiklos_Hollender Posts: 1,589Member
    And you gonna do things like add quotation marks and escape already existing quotation marks? In a more modern version like 17 or 18, one can use the CSV Buffer table. Unfortunately I have a similar problem in NAV2015, so I will probably backmigrate half of the functionality of the CSV Buffer...
  • Jacob1227Jacob1227 Posts: 82Member
    Thanks tally sachin and Miklos.

    Tally,I have done it.Can you please tell me how to include a header?
  • TallyHoTallyHo Posts: 282Member
    Do you want to include a header in a csv file?
  • Jacob1227Jacob1227 Posts: 82Member
    Yes Tally.
  • TallyHoTallyHo Posts: 282Member
    edited 2019-06-26
    OnPreDataItem()
    IF FILE.EXISTS(<Your FileName>) THEN
    FILE.ERASE(<Your FileName>);

    fileExport.CREATE(<Your FileName>);
    fileExport.TEXTMODE := TRUE;
    fileExport.WRITEMODE := TRUE;
    fileExport.WRITE(STRSUBSTNO('%1;%2;%3;%4;..",
    <Your Header Values>);

    OnAfterGetRecord()
    fileExport.WRITE(STRSUBSTNO('%1;%2;%3;%4;..",
    DELCHR(<Your Values>),'=',STRSUBSTNO('";');

    OnPostDataItem()
    fileExport.CLOSE;
  • Jacob1227Jacob1227 Posts: 82Member
    Hi Tally,

    I have tried with your code but not able to include a header.

    please look at my code and suggest me the changes.

    7k831hbt5zye.png


  • TallyHoTallyHo Posts: 282Member
    Please post all lines of code as text, I Will correct them
  • Jacob1227Jacob1227 Posts: 82Member
    Hey Tally,
    I got it .It works well now.Header also included.Thank u once again.
Sign In or Register to comment.