Search code examples
lotus-noteslotus-dominolotusscript

Programmatically change the value of a field without entering editmode and still refresh form


In my Lotus Notes application (classic, not using XPages), the user won't be able to edit documents directly.

Instead, modifications will happen dialog-based and triggered through actions on the form.

For example, I have an action invoking code similar to the following:

Dim ws As New NotesUIWorkspace
Dim result As String
Dim document As NotesDocument
Dim options(1 To 6) As String

'... - Fill options

Set document = ws.CurrentDocument.Document
result = ws.Prompt(PROMPT_OKCANCELCOMBO, "New Value", "Please choose the new value", document.Foo(0), options)

If result <> "" Then
    document.Foo = result

    Call document.ComputeWithForm(False, True)
    Call document.Save(True, False)
End If

This updates the value of Foo to the value the user chose in the dialog.

However, this new value is not shown to the user - the Form does not seem to be refreshed.
Reopening and closing the form does show the new value; it definitely gets updated.

The nearest I could get was the following code (inside the if-block):

ws.CurrentDocument.EditMode = True
document.Foo = result
Call ws.CurrentDocument.Save()
ws.CurrentDocument.EditMode = False

Nevertheless, this solution seems a bit suboptimal to me as I have to enter edit mode.

How can I refresh the form using Notes Script to reflect the change of the field without having to enter edit-mode?
Methods like ws.CurrentDocument.Refresh either don't show any effect or raise errors as they can't be used outside edit-mode.

Many thanks in advance for your ideas, tips and solutions!


Solution

  • I found another solution avoiding entering edit-mode:

    As the documentation to Reload states:

    Modifications made to the back-end document outside the current editing session (for example, by an agent or another user) do not appear until the document is closed and reopened. You can close and reopen a front-end document with NotesUIDocument.Close(True) and NotesUIWorkspace.EditDocument.

    Thus, the document can be "refreshed" (with a bit of flickering) using:

    Dim ws As New NotesUIWorkspace
    Dim document As NotesDocument
    Set document = ws.CurrentDocument.Document
    '...
    Call ws.Currentdocument.Close(True)
    Call ws.Editdocument(False, document)