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)

This entry was posted in Lotus Domino, Show-n-Tell+Thursday. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

9 Comments

  1. Posted February 24, 2006 at 6:07 pm | Permalink

    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. Alipasha
    Posted February 26, 2006 at 6:25 am | Permalink

    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. Posted February 28, 2006 at 9:02 am | Permalink

    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. soumen
    Posted August 7, 2006 at 2:50 am | Permalink

    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. Edward
    Posted November 29, 2006 at 4:37 pm | Permalink

    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. Michiel
    Posted September 20, 2007 at 5:39 pm | Permalink

    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….

  7. User08
    Posted October 22, 2008 at 4:00 am | Permalink

    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??

  8. Michael
    Posted February 3, 2009 at 12:44 am | Permalink

    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…

  9. Lawrence
    Posted April 24, 2009 at 6:03 am | Permalink

    Late in… but I’ve used for the past few years

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

2 Trackbacks

  1. [...] But the QuerySave is were to test for unqiues, before the document is saves, and if that fails I popup a nice user friendly error message and the stop the save to change the value, or close with out saving. [...]

  2. [...] ce am citit articolul Building a better “Save & Exit” action button in Lotus Notes formula language, articol care descrie crearea unei formule optime pentru butonul de [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*