In Classic Client we are used to use the variable type File to write to a text file.  In these cases we have had to convert the Icelandic characters from CP850 to ISO-8859-1 for this to be saved correctly.  In Role Tailored Client this file is created on the server and you will have to download the file to the client computer and save it there.

There is an easy solution to this.  Simply use the automation ‘Windows Script Host Object Model’.TextStream.  First you need to create a file system object ‘Windows Script Host Object Model’.FileSystemObject.
[code htmlscript=”false”]CREATE(SystemShell,TRUE,TRUE);
SystemTextStream := SystemShell.CreateTextFile(TheFileName,TRUE);[/code]
where SystemShell is Automation ‘Windows Script Host Object Model’.FileSystemObject and SystemTextStream is Automation ‘Windows Script Host Object Model’.TextStream

For each line you need to write to the file you do
[code htmlscript=”false”]SystemTextStream.WriteLine(Line);[/code]
and the in the end you close the stream and thereby the file.
[code htmlscript=”false”]SystemTextStream.CLOSE;[/code]
if the CREATE function use TRUE,TRUE then the automation is created on the client side and the file will be created on the client computer.

There are dotnet objects available to do the same thing if you are only running Role Tailored Client.

3 thoughts on “Writing to a text file

  1. rathin says:

    Dear Gunnar’s,

    i have one query please explain . In XML port we can import text file . during import the text file into the table how to group the records .

    for example i having the below fields in my table .

    Doc Type, Doc no.,Line No,item,qty

    in text file i have values like this
    “order”,”10001,”10000″,1002,10
    “order”,”10001″,”20000″,1002,10

    during import the Qty value should be grouped based on(Doc type,docno,item) in table
    table record should be order,10001,10000,1002,20

    thanks,
    Rathin

    1. By reading the data into TempSalesLine you can use this example code to group the entries.

      WITH TempSalesLine DO BEGIN
      SETCURRENTKEY(“Document Type”,”Document No.”,Type,”No.”);
      IF FIND(‘-‘) THEN REPEAT
      SETRANGE(“Document Type”,”Document Type”);
      SETRANGE(“Document No.”,”Document No.”);
      SETRANGE(Type,Type);
      SETRANGE(“No.”,”No.”);
      CALCSUMS(Quantity);
      SalesLine := TempSalesLine;
      SalesLine.INSERT;
      FINDLAST;
      SETRANGE(“Document Type”);
      SETRANGE(“Document No.”);
      SETRANGE(Type);
      SETRANGE(“No.”);
      UNTIL NEXT = 0;
      END;

  2. rathin says:

    Thanks for your reply.

Leave a Reply

%d bloggers like this: