Thursday, January 10, 2008

SnTT: Canceling an Embedded Editor Transaction

If you use embedded editors in your design, you may have run across this issue. The user starts to edit a document, only to decide that they want to select another one from the view or cancel edit mode. Unfortunately, this isn't handled very elegantly by Notes. What you get is the error message shown below.

Basically, once you start editing a document in an embedded editor control, Notes expects you to save the document. Since this is the case, we can use this fact to make a simple addition to our embedded editor. Here's my approach.

Create a new action (via a button, link, whatever makes sense) to allow the user to cancel the edit transaction. Since Notes needs the document to be saved, add some computed for display (CFD) fields on the embedded editor form to hold the initial values of the fields you are exposing for editing. Set the value of the fields like this:

When the doc is opened in the embedded editor, these CFD fields will get set to the starting values of their corresponding fields. If you want to cancel the edit transaction, you just need to set the fields back to their initial values, then save the doc. Something like this:

7 comments:

Form has two row table, top row embedded editor that displays only action button.Row 2 = embedded single cat view.

Editor has 7 main actions each with 7 subactions.The editor must enter and exit edit mode because I have code in a subform that triggers on PostOpen and QuerySave to generate an audit trail.

Click a button, some fields get set.Click another button, the code seems to execute (I may ask the user for input), but nothing is updated.Click the same button again, it works.Click it again, it doesn't.Click it again, it does.

Every other time, the code executes properly.

If I Single click the doc in the embedded view.Hit an action.Click the doc againHit an action.Everything works every time.

It seems that the embedded editor is looksing focus on its own document.

FWIW, this is turning into a rather knarly problem. I am having a problem, I know, with the order I'm executing some code - the into and out of edit mode stuff is killing me. I tried to move most code into an agent called by the action or form button but it's looking that that's not going to work (maybe converting from @Code to LS might help?).My brain is fried - going away for now...back later.

In the code, one of the things I want/need to do is test to see if a field is being changed and, if it is, ask the user for a reason.

Turns out issuing an @Prompt causes the embedded editor and embedded view to uncouple and many bad things happen - most notably, the problem of the code running every other time you try and use the action button.

If I replace the Prompt with a hard coded string, the code works fine.