Search code examples
lotus-noteslotusscript

Lotus Notes: Creating new document with prefilled fields, opening in edit mode without saving


I have an issue I don't quite understand and I'm struggeling with it for quite a while now.

From an existing document I want to create a new document (same DB different form). I use a button inside this form.

Sub Click(Source As Button)
    Dim ws As New NotesUIWorkspace
    Dim thisProject As New kitcProject() '// this only wraps the current document
    Set NREDOC = thisProject.newNREdocument() '// this returns a NotesDocument, that has not been saved yet
    Call ws.EditDocument(False, NREDOC, False, "", True, False)
End Sub

This is not working, it does not open the document unless I save it first before using the EditDocument call

    Call NREDOC.Save(true, false)

I have a similar button function that works fine with a document from another database, that is also in unsaved state when opening it with the EditDocument call.

Here is the function that returns the NREDOC

%REM
Function newNREdocument
Description: Returns a new NotesDocument prefilled of type NRE
%END REM
Public Function newNREdocument() As NotesDocument
    Set me.nreDoc = db.Createdocument()
    With me.nreDoc
        .Form = "NRE"
        .nreProjectID = me.uidocument.FieldGetText("prProjectID")
        .nreProjectName = me.uidocument.FieldGetText("prProjectName")
    End with
    Set newNREdocument = me.nreDoc
End Function

Checking the NREDOC in Debug Mode tells me that there is nothing wrong with the document, ParentDatabase is set correctly, all the prefilled values are set, but it won't open. What am I doing wrong?

Is there some flag to be set in the form properties maybe? I have no further ideas

Thanks for your help in advance.


Solution

  • I found the solution. The key here is the newInstance flag at the end

    Call ws.EditDocument(True, NREDOC, False, "", False, True)
    

    Setting the flag to True solved my issue. Unfortunatelly that was the last flag I was playing around with.