Building a better “Save & Exit” action button in Lotus Notes formula language

Something I’ve seen far to often is a Lotus Notes “Save & Exit” action button that does this, in formula language:

@Command([FileSave]);
@Command([FileCloseWindow])

It’s quick and easy formula language, and seems to do the job. However, it is also sloppy.

The Problem: if the “Save” fails (say, because of validation), it still tries to do the “FileCloseWindow”, which causes another promoting to save (which will still fail), and if you cancel that, the form closes without saving any changes. Result: lost work; no change to correct; and very annoyed users.

Instead use this, which does the same thing, but much better:

@If(@Command([FileSave]);@Command([FileCloseWindow]);””)

The “FileCloseWindow” gets executed only if the “Save” is successful. Just as quick and easy, and much more robust.

This way of doing it has been available at least Notes R3, which is the before the mid 90’s. For the record we are up to R7, now.

Brought to you by the letter S, and , via . And Notes Nerd links in with Sloppy Saves

Update: Thanks for the link love Ed! via Show n tell exposes sizeable talent…Talent – maybe, Exposure – no doubt! (Ed Brill is the Business Unit Executive for the Worldwide Lotus Messaging Sales, IBM Software Group)

11 Replies to “Building a better “Save & Exit” action button in Lotus Notes formula language”

  1. This actually ties in well with my first SNTT post from last week on modular form validation. What I forgot to mention in that post is that since you’re interrupting the querysave by popping up a validation dialog, a “normal” filesave/fileclose action button will raise an error.

    The solution I had was to use a Lotusscript button with the following code:

    Sub Click(Source As Button)
    On Error Goto FINISH

    Call uidoc.save ‘ if validation fails, this line should generate an error
    ‘If no error generated, then lets continue…
    Call uidoc.close()

    FINISH:
    Exit Sub

    End Sub

    Essentially does the same thing as yours, but with way too many keystrokes. Great tip, thanks!

  2. Great Tip from Kevin Pettitt, if you want to save and close through LotusScript. Just one remark though: How about instead of:

    On Error Goto FINISH

    we used

    On Error 4411 Goto FINISH

    as 4411 stands for SAVE UIDOCUMENT ERROR

    I would also put an END or EXIT SUB after the close statement, just to be sure the code after the FINISH label is not processed. So my Alternative Code would look like this:

    Sub Click(Source As Button)
    On Error Goto FINISH

    Call uidoc.save ‘ if validation fails, this line should generate an error 4411
    ‘If no error generated, then lets continue…
    Call uidoc.close()

    Exit sub
    FINISH:
    Exit Sub
    End Sub

  3. Alipasha, thanks for the suggestion. Your version is definitely “cleaner”, but unless you have some special way to handle that particular error, as opposed to some other kind of error (not sure what other errors this code is likely to experience), it doesn’t really make any difference.

    That said, if you’re really doing your error trapping right, and want to be able to write out “real” errors, you would not want to log a 4411 error, but you would any other error. Therefore, the code would end up like this:

    Sub Click(Source As Button)
    On Error 4411 Goto FINISH
    On Error Goto ErrorHandler

    Call uidoc.save ‘ if validation fails, this line should generate an error
    ‘If no error generated, then lets continue…
    Call uidoc.close()

    Exit Sub

    ErrorHandler:
    ‘Log “real” error using whatever error logging approach you have

    FINISH:
    ‘This is a UIDoc Save error, which is routine and doesn’t need to be logged
    Exit Sub

    End Sub

  4. Dear Alipasha/Pettitt ,

    thanx for your tips. i was suffering from closing document through lotusscript for a long time. your tips really help me a lots.

    regards,

    soumen

  5. I have been using the same formula language save & exit action button that you have created here, but recently found that it gives a “Cannot execute the specified command” error if I try to use it when the document is in read mode.

    We cannot possibly save a document that is in read mode, of course, which leaves this button not only redundant but also potentially worrying for any user that does try to use it in read mode. I would like to suggest that this ‘Save & Exit’ action button be hidden in read mode.

  6. Pingback: False Positives » Blog Archive » SNTT : Test for Unique values in a Lotus Notes Form field

  7. This is a great tip! I had issues with this while using form validation in conjunction with an action button performing @Command([FileSave]). But the thing that’s really sloppy is that there’s nothing in the Notes documentation about that command returning a True/False….

  8. I have a save button which contains validations for number of fields. I would like to add something to querysave that would call this save button rather than have to write new code in query save for these field validations is this possible??

  9. So funny! Every time I forget how to check this I do a search and you are the top hit. A good reminder of our past working days…

  10. Pingback: cotârlea.ro » Blog Archive » Lotus Notes/Domino “din mers” :: Lotus Notes/Domino - Romania

Leave a Reply