Subject: RE: It’s all about scope and context…
Thanks for the competent input from the both of you, Beau and Rocky.
I understand that objects/variable within the module of a function will be extinguished when the function completes, however it is most disturbing news to me that the resulting expression of a function anyhow won’t necessarily be conveyed back to the call of the function – in particular as the resulting value is a reference to an existing document.
My problem is that when I make the call to
Function GetReport (doc as NotesDocument) as NotesDocument
in the statment
Set docReport = GetReport(note)
I don’t know in which database the resulting docReport is stored.
Function GetReport identifies the dbTarget within itself, by a call to another function GetDb as NotesDatabase, which looks up a dbReplicaID from a set-up document and then finally
Set docOld = dbTarget.GetDocumentByUNID(doc.ReportID(0) )
Set GetReport = docOld
End Function
(The point has been to simplify/standardize for reuse/maintenance and taking care of the handling of various other things that goes on besides this, otherwise the calling script could directly have stated
Set docReport = dbTarget..GetDocumentByUNID(note.ReportID(0) )
which appearantly would have avoided the problem now encountered.)
So from what you guys are saying, I will have to complicate things a little more in the calling script by adding there first a call to the functon GetDb and then send the resulting db into the GetReport as an additional parameter?
Alternatively, I should establish a global variable for the dbTarget that can be sent as the additional parameter.
The functions GetReport and GetDb are parts of a script library, while the script calling GetReport could be anywhere (including in the same script library). Will it then be sufficiant to have that global db-variable declared in the Declarations part of the script library?