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 NAV (Archived)

Export purchase lines to text

(0) ShareShare
ReportReport
Posted on by

Hi everyone, 

I'm using nav 2016 and I need to export some purchase lines to a text file. 

At the moment I know how to create the file, download to the client but how to get the specific lines this image show below? I have a page (purcha quote) where I have a page part called "PurchLines" linked to Purchase Quote Subform in PagePartId. 

2742.purchase-lines.png

At the moment I have this code

TXT - OnAction()
// LACPOS001
MESSAGE('WORD');

Serverfilename := FileManagement.ServerTempFileName('txt');
ClientFilePath := 'C:\teste.txt';  

MyFile.CREATE(Serverfilename);
MyFile.CREATEOUTSTREAM(MyOutStream);

IF PurchaseLine.Find('-') THEN
  REPEAT
    counter := counter+1;
    //MyOutStream.WRITETEXT('9525200001 22-08-18	0	1,1'); 
    //MyOutStream.WRITETEXT(); // This command is to move to next line
  UNTIL PurchaseLine.Next = 0;


//MyOutStream.WRITETEXT('9525200001 22-08-18	0	1,1'); 
MyFile.CLOSE;// To end the writing and write out to the file.

FileManagement.DownloadToFile(Serverfilename,ClientFilePath);

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    Not so clear the question... you have to compose the string that you are passing to WRITETEXT with the values you want to have in the file.

    I suppose the data is in your PurchaseLine record you're looping.

  • Community Member Profile Picture
    on at

    I want to create a text file in this case with 4 purch lines with fields item no, date, qty, price ('9525200001 22-08-18 0 1,1');

    I don't know how to dinf how many loops I have, that depends of the amount of purch lines (in this case are 4). So I will need 4 lines in my txt file like this "'9525200001 22-08-18 0 1,1' with information contain in the purchase line

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    I think you need to filter the Purchase Lines for every order, isn't it? Do you need a file for every Purchase Order?

    PurchaseLine.SETRANGE("Document Type",PurchaseLine."Document Type"::Order);

    PurchaseLine.SETRANGE("Document No.",'XXX'); //Where XXX is your order number (PurchaseHeader."No.")

    IF PurchaseLine.FINDSET THEN

     REPEAT

       counter := counter+1;

       MyOutStream.WRITETEXT(PurchaseLine."No." + FORMAT(PurchaseLine."Order Date") + FORMAT(PurchaseLine."Unit Cost") + FORMAT(PurchaseLine.Quantity);

       MyOutStream.WRITETEXT(); // This command is to move to next line

     UNTIL PurchaseLine.Next = 0;

    The WRITETEXT string should be formatted as your needs.

  • Community Member Profile Picture
    on at

    I will try this code, the separation is with TAB

  • Community Member Profile Picture
    on at

    varTab := 9; (char)

    txtTab := format(varTab); (text)

    And then in my writing to the file:

    File.Write(Field1 + txtTab + field2 + txtTab + Field3 ...);

    i will try this example

  • Community Member Profile Picture
    on at

    So now I have this,

    TXT - OnAction()
    // LACPOS001
    varTab:=9;
    
    txtTab:=FORMAT(varTab);
    
    Serverfilename := FileManagement.ServerTempFileName('txt');
    ClientFilePath := 'C:\Catia\teste.txt';
    
    MyFile.CREATE(Serverfilename);
    MyFile.CREATEOUTSTREAM(MyOutStream);
    
    PurchaseLine.SETRANGE("Document Type",PurchaseLine."Document Type"::Quote);
    PurchaseLine.SETRANGE("Document No.", PurchaseHeader."No.");
    
    MESSAGE('numero docuemnto %1 ',FORMAT(Rec."No.")); //TESTE
    MESSAGE('tipo documento %1 ',FORMAT(Rec."Document Type")); //Proposta
    
    IF PurchaseLine.FINDSET THEN
    REPEAT
    counter := counter+1;
    MyOutStream.WRITETEXT(PurchaseLine."No." + txtTab + FORMAT(PurchaseLine."Data Tabela") + txtTab + FORMAT(PurchaseLine.PVP) + txtTab + FORMAT(PurchaseLine.Quantity));
    MyOutStream.WRITETEXT(); // This command is to move to next line
    UNTIL PurchaseLine.NEXT = 0;
    
    
    MyFile.CLOSE;// To end the writing and write out to the file.
    
    FileManagement.DownloadToFile(Serverfilename,ClientFilePath);
    
    

    But is not writing. The file is empty because the "if" condition is not true. That's weird to me because in "purchase line" table I have these lines for the "document no." with "teste" and for "document type" proposta (quote)

    linhas-purchse.png

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 NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans