Subject: RE: copyallitems creates a document
Here’s the initialise code, which then calls one of a number of subs, like the one posted previously.
Sub Initialize
On Error Goto SETUP_ERROR
Set session = New NotesSession 'declare the notessession
Dim datadb As notesdatabase 'declare a notesdatabase (this will be the data dictionary)
Dim db_filepath As String 'string to hold the full path & filename of this database
Dim db_filename As String 'string to hold the filename of this database
Dim app_filepath As String 'string to hold the filepath for the applications
Dim dd_filename As String 'string to hold the data dictionary filename
Dim dd_filepath As String 'string to hold the data dictionary filepath
Dim viewSource As NotesView
Set db = session.CurrentDatabase 'set the database to the current database
db_filepath = db.filepath 'set a variable to hold the file path
db_filename = db.filename 'set a variable to hold the file name
app_filepath = Strright(replacesubstring(getLocalKeyword(db, "PortalDataDictionaryPath"), "/", "\"), "\") + "\"
dd_filename = getdatadictionary(db) 'get the data dictionary filepath
dd_filepath = app_filepath + dd_filename 'the filepath to the data dictionary
agentlogpath = app_filepath + getKeywordvalue(db, dd_filepath, CONST_AGENTLOG, "System") 'get the path to the agent log database
Call initlog(agentlogpath, "Details", db.Server, "Get CRM Record") 'open the agent log
On Error Goto processError 'on error go to processError
'------------------------------------------------------------------------------------------------------------------------------------------------------------------
'Agent specific variables
Dim dbSource As New NotesDatabase( "", "" )
Dim formType As String, RecordID As String, sourceDBID As String, vw As String, navDB As String
Set docContext = session.DocumentContext
docContext.SaveOptions = "0"
'------------------------------------------------------------------------------------------------------------------------------------------------------------------
'Logging set up - START CODE HERE
queryString = QueryStringToList(docContext.Query_String(0))
formType = queryString("FormType")
vw = queryString("SourceVW")
’ Call logmsg("Query_String: " + docContext.Query_String(0), True)
navDB = queryString("SourceDBID")
If Iselement(queryString("replySource")) Then
RecordID = queryString("replySource")
If Iselement(queryString("RecordID")) Then
sourceID = queryString("RecordID")
Elseif Iselement(queryString("SourceDBDoc")) Then
sourceID = queryString("SourceDBDoc")
End If
If Iselement(queryString("replyType")) Then
replyType = queryString("replyType")
End If
Elseif Iselement(queryString("RecordID")) Then
RecordID = queryString("RecordID")
Elseif Iselement(queryString("SourceDBDoc")) Then
RecordID = queryString("SourceDBDoc")
End If
SourceDB = queryString("SourceDBID")
sourceDBID = queryString("SourceDBID")
'Clear the error field
docContext.SaveError = ""
'Get hold of the source database and document
If Not dbSource.Open("", SourceDB) Then
docContext.SaveError = "Error: Unable to open source database"
Goto CLEAN_EXIT
End If
Set docSource = dbSource.GetDocumentByUNID(RecordID)
Set viewSource = dbSource.GetView(vw)
’ Call logmsg("viewSource: " + viewSource.IsPrivate, True)
’ Call logmsg("viewSource: " + Cstr(viewSource.entryCount), True)
If docSource Is Nothing Then
docContext.SaveError = "Error: Unable to open source database document"
Goto CLEAN_EXIT
End If
Select Case formType
Case "Communication%20Record" :
Call loadCommsRecord
Case "Memo" :
Call loadEmail
Case "Fax%20Out" :
Call loadFaxOut
Case "Report" :
Call loadReport
Case "Letter%20Out" :
Call loadLetter
Case "incoming%20correspondence" :
Call loadIncCorrespondence
Case "reply" :
Call loadReply(sourceID)
End Select
If replyType = "noattach" Or replyType = "allnoattach" Or replyType = "fwdnoattach" Then
Call docContext.RemoveItem("AttachmentList")
Call docContext.RemoveItem("AttachmentSizes")
Elseif replyType <> "" Then
docContext.GetAttach = "True"
Else
Call setupAttachments(docSource, docContext)
End If
docContext.ShowPortalActions = "True"
'docContext.window_title = docSource.ViewSubject(0)
'If dbSource.IsOpen Then
Call loadNavigation(dbSource, viewSource, navDB)
'End If
'END CODE HERE
'------------------------------------------------------------------------------------------------------------------------------------------------------------------
CLEAN_EXIT:
Call endlog() 'close the agent log
Exit Sub
'ERROR HANDLING
SETUP_ERROR:
Msgbox "Error in Get CRM Record agent setup. Line: " + Cstr(Erl) + " Error: " + Error()
Exit Sub
processError:
Call logerr(Err(),Error() + " at line number " + Cstr(Erl()) +" : Initialise; dbSource "+dbSource.FileName+" vw "+ vw +" navDB "+ navDB ,False) 'log the error in the agent log
Resume Next
End Sub
Thanks
Jon