Order of Execution

I’m confused…I have a button that is checking to make sure that 4 fields are populated before letting the document save. Here is my code:

@If(Category = “”; @Return(@Prompt([Ok]; “Error”; “Category must be populated in order to Save”));

@If(AssignedAnalyst = “Helpdesk”; @Return(@Prompt([Ok]; “Error”; “You must assign the ticket to an analyst in order to Save”));

@If(AssignedAnalyst = “”; @Return(@Prompt([Ok]; “Error”; “Assigned Analyst must have a name in order to Save”));

@If(ProblemTitle = “”; @Return(@Prompt([Ok]; “Error”; “Problem Title must be populated in order to Save”));

“”))));

@PostedCommand([FileSave]);

@PostedCommand([FileCloseWindow])

This is where it gets confusing. If I click the button and none of the above are populated, I am prompted to populate the “Category” field. Then it saves and closes. But it shouldn’t save and close because the other fields aren’t populated.

No matter what order it checks above (if Category is listed first or last), it only checks the Category first, then saves & closes.

More odd yet - If I re-edit the same ticket (now with the category populated), it asks me for the next field.

Is there a better way of performing this validation that these fields are populated without allowing the document to save and close??

Thank you.

Subject: Order of Execution

Yes. Use the Field Validation events of the individual fields, and make you button merely:

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

Never count on users clicking on your buttons when they can do things another way. Input Validation event code will prevent the user from saving – your code won’t. (Hitting ESC and answering “Yes” will save, as will File->Save, CTRL+S, clicking the floppy icon, …)

Subject: RE: Order of Execution

Absolutely what this rookie was looking for. Works perfectly! I thank you so much for the “Save” code - that’s very helpful.

Subject: RE: Order of Execution

OK - So I do have one question about this “Save” code. When I press the Save & Close button, it asks me if I want to save the document. Any clue why its redundant?

Subject: RE: Order of Execution

Weird – that is precisely the problem that the code is meant to get around. Let me explain.

The naive code for a Save&Close action is as simple as it sounds:

@Command([FileSave]);

@Command([FileCloseWindow])

That works, and works well, provided that the document can be saved. If the FileSave fails (as it would for a failed input validation), there is nothing to stop FileCloseWindow from happening. However, Notes will recognise that the document has been “touched” by the user, and will offer to save changes before closing the window. The code I gave:

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

takes advantage of the fact that most @Commands actually have a return value – @True (1) for success or @False (0) for a failure. If the FileSave is not successful due to Input Validation or a no-continue condition in the QuerySave event, then it returns false and the FileCloseWindow should not be called.

If you are still getting a Save Options dialog, then look for code somewhere that may be changing a field value after the document is saved.

Subject: RE: Order of Execution

From the Designer 6 help for for the “FileSave” command:

When you follow this command with the FileCloseWindow @command, by default Notes displays a dialog box prompting users to save the document they are closing. The document will be saved even if a user clicks “No” in the dialog box. To prevent this dialog box from displaying, add a hidden field to the form named “SaveOptions” and set its value to zero (“0”). You do not need to add the SaveOptions field if you follow this command with the CloseWindow @command instead of FileCloseWindow.

In other words, for your “save and close” button to work in Notes 6 without prompting the user to save, either use @Command([CloseWindow]) instead of @Command([FileCloseWindow]), or add a SaveOptions field and it to “0” before the FileCloseWindow command.

Note that if this button must work in Notes 5, you can’t use @Command([CloseWindow]).

I’ve done development for several applications that are still being used with Notes 5, and buttons calling @Command([FileSave]) followed by @Command([FileCloseWindow]) never prompt the user to save, so there seems to have been a change in Notes 6.

Subject: RE: Order of Execution

  1. FileCloseWindow after a successful FileSave does not raise a prompt unless the data have changed between the save and close. This can be empirically tested.

  2. The @If structure given does not call the FileCloseWindow unless the FileSave was successful.

  3. Therefore there must be a data change between the save and close, meaning that setting SaveOptions to “0” will prevent saving of the change.