Matthias
Matthias

Reputation: 12269

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!

Upvotes: 1

Views: 6807

Answers (4)

user3061674
user3061674

Reputation: 1

Lets say you have a table. You want to show the next row to add an order item or something:

@setfield("NumOrders";NumOrders+1);
@Command( [ViewRefreshFields] )  

You need a hidden field NumOrders, then refresh will work.

@Command( [ViewRefreshFields] )

It's that easy!

Upvotes: 0

Matthias
Matthias

Reputation: 12269

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)   

Upvotes: 2

JiKra
JiKra

Reputation: 1800

If your user has editor rights in that document, you are not able to stop him to bypass any script action in your form and simply edit it.

Better way to let user edit only particular fields is Controlled Access Section.

Upvotes: 1

Ken Pespisa
Ken Pespisa

Reputation: 22284

Your answer is the best one. Going into edit mode and either setting the field and saving or simply refreshing the page after you've already set the field is the right idea. It's unfortunate but necessary.

The user will need edit rights to the document of course which presents another problem. How do you prevent the user from typing control E or clicking a smart icon to edit the document?

For that you can set a Global variable that controls access to editing the document. When you're opening your dialog you can set that global variable to true and then set it back to false after you've made your changes. In the query mode changed event set continue to the value of that global variable.

Upvotes: 1

Related Questions