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 Member Posts: 416
    I hate to say.. 😁
    Tomorrow you'll have an example. If no one beats me to it.
  • Sachin_Sachin_ Member Posts: 67
    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 Member Posts: 416
    Remove file only when it exists.
  • Miklos_HollenderMiklos_Hollender Member Posts: 1,598
    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 Member Posts: 128
    Thanks tally sachin and Miklos.
    TallyHo wrote: »

    Tally,I have done it.Can you please tell me how to include a header?
  • TallyHoTallyHo Member Posts: 416
    Do you want to include a header in a csv file?
  • Jacob1227Jacob1227 Member Posts: 128
    Yes Tally.
  • TallyHoTallyHo Member Posts: 416
    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 Member Posts: 128
    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 Member Posts: 416
    Please post all lines of code as text, I Will correct them
  • Jacob1227Jacob1227 Member Posts: 128
    Hey Tally,
    I got it .It works well now.Header also included.Thank u once again.
Sign In or Register to comment.