Search code examples
lotus-noteslotus-dominolotusscriptlotuslotus-formula

Lotus Notes: Create a text file


I am trying to create a text file in lotus notes which I am running through the agents. The agent ran successfully but the text file is not created in the path which is specified in the lotus script.

This is the lotus script code:

Option Public
Sub Initialize  
    MsgBox " Agent AccessUserList"
    On Error GoTo HandleError   
    Dim session As New NotesSession
    Dim myStream As NotesStream
    Dim TheDate As String, filename As String 
    TheDate=Format(Now(),"mmdd")    
    filename = "C:"+"\red"+"\color"+TheDate+".txt"
    MsgBox filename
    Set myStream = session.Createstream()
    MsgBox "MySTREAM2"
    Call myStream.Open(filename, "ASCII")
    MsgBox "MySTREAM3"
    Call myStream.Truncate()
    MsgBox "Entered View"

closeFile:
    Call myStream.Close()
    MsgBox "Closed"
    Exit Sub
HandleError:     
    MsgBox "Error  - " & Error &" at line number  " & Erl
    Exit Sub    
End Sub

I have scheduled to 5 min to check whether it creates a new file in specified folder

enter image description here

And also the privileges while scheduling I used both second and third Allow restricted operations Allow Restricted operations with full administrator rights

But still it shows the folder as empty but the folder time would be changed when this it gets scheduled.

To test it i scheduled the agent to run locally as well as in the server. But the error is same the text file is not created.

Agent log is not having any errors.

enter image description here

I have checked in the logs as well and there is no errors. Can anyone tell what is the mistake in the above code and why my file is not getting created when the agent executes correctly.


Solution

  • NotesStream doesn't work for you as you just want to create an empty file.
    Call myStream.Close() always deletes just now created file if it's empty at this point.

    Use traditional FreeFile()/Open/Close instead:

    Sub Initialize
        On Error GoTo HandleError   
        Dim TheDate As String
        Dim filename As String 
        Dim fileNum As Integer
    
        TheDate = Format(Now(),"mmdd")    
        filename = "C:\red\color" + TheDate + ".txt"
        fileNum = FreeFile
        Open filename For Output As fileNum
        Close fileNum
    
    Finally:
        Exit Sub
    
    HandleError:     
        MsgBox "Error  - " & Error &" at line number  " & Erl
        Resume Finally    
    End Sub