Copyallitems creates a document

Hello

I have a web application with a forms database which is used to view documents in other databases. To make it work when a form is viewed I do a “copyallitems” from the source document to a temporary document in the forms database.

I am not calling save at all at any point in creating the temporary document (all done via script) however a document is getting saved. Has anyone seen this before and if so how did you resolve it ?

At the moment I have a clean up agent running overnight which works, but I’d like to work out why the documents are being created in the first place.

Any help appreciated

Thanks

Jon

Subject: copyallitems creates a document

post your code

Subject: RE: copyallitems creates a document

Hi, code is as follows (this is just the sub routine, some variables are set in the initialise statement)

Sub loadEmail

On Error Goto processError	

'------------------------------------------------------------------------------------------------------------------------------------------------------------------

'Sub specific variables

Dim rtBody As NotesRichTextItem

'------------------------------------------------------------------------------------------------------------------------------------------------------------------

'Logging set up - START CODE HERE

With docContext

	

	Call docSource.CopyAllItems (docContext, True) 'docSource is set globally

	

	.SourceDBID = SourceDB 'Source DB is set globally

	.SourceDBDoc = docSource.UniversalID

	.SourceFormName = docSource.FormName(0)

	.recordID = docSource.UniversalID

	

	.SendFlag = docSource.SendFlag(0)

	

	

End With

'END CODE HERE

'------------------------------------------------------------------------------------------------------------------------------------------------------------------

Exit Sub

'error handling

processError:

Call logerr(Err(),Error() + " at line number " + Cstr(Erl()) + " : loadEmail",False) 'log the error in the agent log

Resume Next

End Sub

Thanks

Jon

Subject: RE: copyallitems creates a document

need to see all the code

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

Subject: RE: copyallitems creates a document

to me it looks like you are setting docContext using notessession.DocumentContext which loads the in memory document, an existing document so it’s not really a temporary document at this point, it’s an existing document, right? are you just not wanting to save any changes to it but they are getting saved, regardless of whether you call a save?

Subject: RE: copyallitems creates a document

Hi Paul

The document context is my case is a form being opened via the web using the ?readform command. When it is opened it is effectively a new document (i.e. it has no field data) and then I copy all the data to it using the copyallitems in a webqueryopen script. It is at this point the document seems to be saved.

Thanks

Jon

Subject: RE: copyallitems creates a document

Just out of curiosity, what happens if you do not use copyallitems but rather copy one item at a time?

Subject: RE: copyallitems creates a document

I could see rich text being a problem, but it is worth experimenting. (I’d also check for SaveOptions and MailOptions on the target doc, since they’d overwrite whatever was done explicitly earlier in the code.)

Subject: RE: copyallitems creates a document

Hi Stan

I think you may be on the right lines here. There is a field called DefaultMailSaveOptions and it has a value of “0”. Any idea if this could be the cause and what the value should be ?

Thanks for you help

Jon

Subject: RE: copyallitems creates a document

I’m not certain what that particular value does (“0” is usually “mostly harmless” is system fields), but it wouldn’t hurt to remove the item, either.

Subject: RE: copyallitems creates a document

maybe that’s just the way it works when a document is loaded in this fashion via the webqueryopen. could not give you a definitive answer on this one but maybe someone who is more familiar with this way of doing it can comment.

Subject: RE: copyallitems creates a document

What happens once the person “finishes” viewing the temporary document on the web? Do they end up doing a submit?

Actually, what is the manner in which you display this temporary document to the web user? Do you use an ?OpenDocument URL?

Subject: RE: copyallitems creates a document

Hi,

I open the document using the ?ReadForm command. The user can do a number of things with the document, including saving changes to it.

I have written a webquerysave agent to handle the submission of the form so it copies all data back to the original document. I have also put a save options field on the temporary form to stop it saving.

The temporary document though is saved when the webqueryopen script runs, and there is no saving going on there, just the copyallitems !

Thanks

Jon