• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

URGENT HELP!

Hi there,

I am hoping to get a response to this quickly as it is due to hand in tomorrow at work, but I spend hours on it trying to work out why it is not working.

Here's the scenario

Basic txt import agent which work quite fine when i don't add the validation of doesfileexist.

First, I need to make sure that in C:\ there is a file called testfile.txt. If this file doesn't exist then the import should not happen. However, if the file exist then I'll need to import it to db specified as the current database, but before the import happens to delete all data in "view1" so that all the fresh data is imported.
Better still, once I've imported this file once, then I need to re-issue a file rename to update the file name on C:\ testfile_old. This will ensure that when the third party system file exports the file the following month(testfile.txt) the correct file will be imported again.

I hope that I made sense.

1. Below is the code with the view deletion which is not working properly.

2. Underneath that, is the code without the view deletion and it is working fine.

Also,when I create the view deletion function separately, it seems to work fine.







1.
Lotus Notes Database Synopsis - Generated at 06:42:51 PM on 03/05/2006
Agent Information
Name:      import agent
Last Modification:      03/05/2006 06:42:40 PM
Comment:      [Not Assigned]
Shared Agent:      No
Type:      LotusScript
State:      Enabled
Trigger:      Manually From Actions Menu
Acts On:      None
LotusScript Code:
Option Public
Sub Initialize
      Dim session As New NotesSession
      Dim db As notesdatabase
      Dim view As notesview
      Dim vcoll As notesviewentrycollection
      Set db = session.currentdatabase
      Set view = db.getview("view1")
      Dim doesfileexit As Boolean
      Dim fileName As String
      Dim txt As Variant
      Dim fileNum As Integer
      Dim doc As NotesDocument
      Dim workspace As New NotesUIWorkspace
      Dim newdoc As notesdocument
      Dim itemA As NotesItem
      'new
      Dim ret As Variant
      Dim colNames(0 To 17) As String      
      colNames(0) = "test1"
      colNames(1) = "test2"
      colNames(2) = "test3"
      colNames(3) = "test4"
      colNames(4) = "test5"
      colNames(5) = "test6"
      colNames(6) = "test7"
      colNames(7) = "test8"
      colNames(8) = "test9"
      colNames(9) = "test10"
      colNames(10) = "test11"
      colNames(11) = "test12"
      colNames(12) = "test13"
      colNames(13) = "test14"
      colNames(14) = "test15"
      colNames(15) = "test16"
      colNames(16) = "test17"
      colNames(17) = "test18"
      fileName$ = "C:\testfile.TXT"
      If Not doesFileExist(fileName$) Then
            Exit Sub
                          else

            Call view.AllEntries.RemoveAll(True)
            Set db = session.CurrentDatabase
            Set doc = New NotesDocument(db)
' Get an unused file number so LotusScript can open a file.
            fileNum% = Freefile()
            Open fileName For Input As fileNum%
            Do While Not Eof(fileNum%)      
               ' Read each line of the file.
                  Line Input #fileNum%, txt
                  If txt <> "" Then
                        ret = Split(txt, "      ")
                        Set doc = New NotesDocument(db)
                        doc.Form = "orderplan"
                        For x = 0 To 17
                              Set item = doc.replaceItemValue(colNames(x), ret(x))
                        Next
                        Call doc.ComputeWithForm(False,False)
                        Print "document created "
                        Call doc.Save( True, True )                  
                  End If
            Loop
            Close fileNum%
      End If
End Sub
Function doesFileExist(strPath As String) As Integer
      doesFileExist = False
      If strPath<> "C:\testfile.txt" Then Exit Function
End Function
            
2.

Working but not complete agent


      Dim session As New NotesSession
      Dim db As notesdatabase
      Dim view As notesview
      Dim vcoll As notesviewentrycollection
      Set db = session.currentdatabase
      Set view = db.getview("view1")
      
      
      Dim fileName As String
      Dim txt As Variant
      Dim fileNum As Integer
      Dim doc As NotesDocument
      Dim workspace As New NotesUIWorkspace
      Dim newdoc As notesdocument
      Dim itemA As NotesItem
      
      'new
      
      Dim ret As Variant
      Dim colNames(0 To 17) As String      
      colNames(0) = "test1"
      colNames(1) = "test2"
      colNames(2) = "test3"
      colNames(3) = "test4"
      colNames(4) = "test5"
      colNames(5) = "test6"
      colNames(6) = "test7"
      colNames(7) = "test8"
      colNames(8) = "test9"
      colNames(9) = "test10"
      colNames(10) = "test11"
      colNames(11) = "test12"
      colNames(12) = "test13"
      colNames(13) = "test14"
      colNames(14) = "test15"
      colNames(15) = "test16"
      colNames(16) = "test17"
      colNames(17) = "test18"
      
      
      fileName$ = "C:\testfile.TXT"
      
      
      Set db = session.CurrentDatabase
            Set doc = New NotesDocument(db)
            
' Get an unused file number so LotusScript can open a file.
            fileNum% = Freefile()
            Open fileName For Input As fileNum%
            
            Do While Not Eof(fileNum%)      
               ' Read each line of the file.
                  Line Input #fileNum%, txt
                  
                  If txt <> "" Then
                        
                        ret = Split(txt, "      ")
                        Set doc = New NotesDocument(db)
                        doc.Form = "orderplan"
                        For x = 0 To 17
                              Set item = doc.replaceItemValue(colNames(x), ret(x))
                        Next
                        Call doc.ComputeWithForm(False,False)
                        Print "document created "
                        Call doc.Save( True, True )                  
                  End If
                  
            Loop
            Close fileNum%
      End If
End Sub


Thank you in advance.
I really appreciate your help with this!!
0
varvoura
Asked:
varvoura
  • 4
  • 3
  • 2
1 Solution
 
cezarFCommented:
hi,

to check if the file exists, try

if Dir$(fileName$, 0) = "" then
   exit function
end if

What is the error with this line Call view.AllEntries.RemoveAll(True)? could it be that you do not have delete rights to the database? if you have, try to explicitly declare a NotesViewEntryCollection object and call its RemoveAll method.

rename the file like this
Name oldName As newName
0
 
varvouraAuthor Commented:
Hi cezarF,

You are the best for responding so soon.
The great news is that I worked out the first part (delete view and re-import using doesfileexist function).

However, renaming the file on C:\drive, I have done yet. I'll attempt your suggestion and see if it works.

Your suggestion is suppose to rename the "testfile.txt" to "testfileold" on C:\. Is this correct?

Could you pls keep an eye on my response. I am about to try, test and reply.

Thanks again.
0
 
cezarFCommented:
here's the code

Close fileNum%
Name fileName$ as Strleftback(Lcase(fileName$),".txt")      & "old.txt"

hope it helps
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
mbonaciCommented:
Hi varvoura,
small suggestion:
rename the file like this:
    testfile_03052006.txt
so you know which file was imported on certain date.

Also move it to the folder OldFiles (it's all done using Name method):
    Name "C:\testfile.txt" As "C:\OldFiles\testfile_" & Format$( Today, "dd.mm.yyyy" ) & ".txt"

Hope this helps,
Marko
0
 
cezarFCommented:
does your doesFileExist function checks for the physical file on c:\, could you share the code? :) it might be better than what i've been using ($dir). :)
0
 
mbonaciCommented:
varvoura,

Function DoesFileExist( directory As String ) As Integer
    On Error Goto ProcessError
    Const ATTR_DIRECTORY = 16
   
    If( Getfileattr( directory ) And ATTR_DIRECTORY ) = 0 Then
        DoesFileExist = True
    Else
        DoesFileExist = False
    End If

    Exit Function    
ProcessError:
    DoesFileExist = False
End Function

Hope this helps,
Marko
0
 
varvouraAuthor Commented:
Hi mbonaci,

I am sorry, I didn't refresh my browser, hence, I didn't see your response until I assigned the point to cezarF. I'll make sure to refresh my browser before I do my final rating.

I'll see if you doesfileexist function works better than mine and use it.

Thank you also for your prompt response and help.
Much appreciated.
0
 
varvouraAuthor Commented:
Hi there,

Name fileName$ as Strleftback(Lcase(fileName$),".txt")     & "old.txt"

work on R6 client and R5 server?

Pls say it does.

Thanks,
Varvoura

0
 
cezarFCommented:
varvoura,

it should. any problem?

if you use Name statement in a sched agent, you need to have run unrestricted agent rights on the server where the agent runs.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now