I need to write a scheduled agent that reads the file from the Windows share and inports the info to the Notes. How do I do that?
Subject: Agent reading info from the file stored in the windows share
If possible, the easiest solution would be to keep a drive letter mapped to the network share. Then you could access the file just like you would if it were on the local file system.
Subject: Agent reading info from the file stored in the windows share
It is certainly possible, but thats a biggish request for the forum.
Here’s an old import script you can use as a starting point. Try some more focused questions if you have difficulties. (This is not tested.)
Sub ImportSections
On Error Goto Errhandle
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Set db = session.CurrentDatabase
' Confirm authorization.
Dim isAdmin As Variant
isAdmin = Evaluate(|@IsMember("[Administration]"; @UserRoles) || @IsMember("[Authoring]"; @UserRoles)|)
If isAdmin(0) = False Then
Messagebox "You do not have sufficient access to use this Action.", MB_OK+MB_ICONSTOP, "Access Restriction"
Exit Sub
End If
' Get file path and name.
Dim filePath As String
filePath = workspace.Prompt (PROMPT_OKCANCELEDIT, "Import Sections", "Please enter a path and file name to the Microsoft Excel (xls) file.", "C:\Sections.xls", "")
If filePath = "" Then
Dim errorString As String
errorString = "You must enter a path to the Sections file." & Chr(10) &_
"Import Sections agent stopped."
Call Messagebox errorString, MB_OK+MB_ICONSTOP, "Import Sections Agent Error"
Exit Sub
End If
Print "Connecting to Excel..."
Dim Excel As Variant
Set Excel = CreateObject("Excel.Application")
Excel.Visible = False
Print "Opening " & filePath & "..."
Excel.Workbooks.Open filePath
Dim xlWorkbook As Variant
Dim xlSheet As Variant
Set xlWorkbook = Excel.ActiveWorkbook
Set xlSheet = xlWorkbook.ActiveSheet
Print "Starting import from Excel file..."
' Set up document processing.
Dim successCounter As Integer
Dim failCounter As Integer
Dim rowCounter As Integer
successCounter = 0
failCounter = 0
rowCounter = 1
Dim success As Variant
Dim answer As Integer
Dim key As String
Do While True
With xlSheet
If .Cells(rowCounter, 1).Value = "Number" Then Goto NextDoc
If .Cells(rowCounter, 1).Value = "" Then Goto Done
key = (.Cells(rowCounter, 01).Value)
Set doc = db.CreateDocument
doc.Form = "Section"
Const ERR_BadField = "A field could not be updated on document "
’ If Not CleanValue ( (.Cells(rowCounter, 01).Value), “Number”, doc ) Then Error 1001, ERR_BadField & key
If Not CleanValue ( (.Cells(rowCounter, 02).Value), "NumberSection", doc ) Then Error 1001, ERR_BadField & key
If Not CleanValue ( (.Cells(rowCounter, 03).Value), "Title", doc ) Then Error 1001, ERR_BadField & key
If Not CleanMulti ( (.Cells(rowCounter, 04).Value), "Description", doc ) Then Error 1001, ERR_BadField & key
success = doc.ComputeWithForm(True, False)
If success Then
successCounter = successCounter + 1
Call doc.Save(True, False)
Else
failCounter = failCounter + 1
End If
NextDoc:
Print "Progress: Item " & Cstr(rowCounter)
rowCounter = rowCounter + 1
End With
Loop
Goto Done
Errhandle:
failCounter = failCounter + 1
answer = Messagebox ("Error" & Str(Err) & ": " & Error$ & Chr(13) & Chr(13) & "Try to continue?", MB_YESNO+MB_ICONEXCLAMATION+MB_DEFBUTTON2, "Document Processing")
If answer = IDNO Then
Resume Done
End If
Resume Next
Done:
Messagebox "Processed " & Cstr(successCounter) & " item(s) successfully." & Chr(13) & Cstr(failCounter) & " Item(s) failed.", MB_OK+MB_ICONINFORMATION, "Document Processing"
Print "Disconnecting from Excel..."
If Isobject(xlWorkbook) Then xlWorkbook.Close
If Isobject(Excel) Then Excel.Quit
Set Excel = Nothing
Print ""
End Sub
Function CleanValue (cleanValue As String, fieldName As String, doc As NotesDocument) As Boolean
CleanValue = False
On Error Goto ErrHandle
Call doc.RemoveItem ( fieldName )
Dim item As NotesItem
Set item = doc.ReplaceItemValue ( fieldName, Fulltrim(cleanValue) )
CleanValue = True
Exit Function
ErrHandle:
Exit Function
End Function
Function CleanMulti (cleanValue As String, fieldName As String, doc As NotesDocument) As Boolean
CleanMulti = False
On Error Goto ErrHandle
Call doc.RemoveItem ( fieldName )
Dim item As NotesItem
Set item = doc.ReplaceItemValue ( fieldName, Fulltrim(Split(cleanValue, Chr(10))) )
CleanMulti = True
Exit Function
ErrHandle:
Exit Function
End Function
Function CleanNum (cleanValue As String, fieldName As String, doc As NotesDocument) As Boolean
CleanNum = False
On Error Goto ErrHandle
Call doc.RemoveItem ( fieldName )
Dim item As NotesItem
Set item = doc.ReplaceItemValue ( fieldName, Val(cleanValue) )
CleanNum = True
Exit Function
ErrHandle:
Exit Function
End Function
Function CleanDate (cleanValue As String, fieldName As String, doc As NotesDocument) As Boolean
CleanDate = False
On Error Goto ErrHandle
Call doc.RemoveItem ( fieldName )
Dim item As NotesItem
If (cleanValue = "") Then
Set item = doc.ReplaceItemValue ( fieldName, cleanValue )
Else
Set item = doc.ReplaceItemValue ( fieldName, Cdat(cleanValue) )
End If
CleanDate = True
Exit Function
ErrHandle:
Exit Function
End Function
Function CleanName (cleanValue As String, fieldName As String, doc As NotesDocument) As Boolean
CleanName = False
On Error Goto ErrHandle
Call doc.RemoveItem ( fieldName )
Dim item As NotesItem
Set item = doc.ReplaceItemValue ( fieldName, Fulltrim(Split(cleanValue, Chr(10))) )
item.IsNames = True
CleanName = True
Exit Function
ErrHandle:
Exit Function
End Function
Function CleanRTF (cleanValue As String, fieldName As String, doc As NotesDocument) As Boolean
CleanRTF = False
On Error Goto ErrHandle
Call doc.RemoveItem ( fieldName )
Dim rtitem As NotesRichTextItem
Set rtitem = doc.CreateRichTextItem( fieldName )
Call rtitem.AppendText( Split(cleanValue, Chr(10)) )
CleanRTF = True
Exit Function
ErrHandle:
Exit Function
End Function