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:

@If(@IsDocBeingLoaded; field_1; @ThisValue)
@If(@IsDocBeingLoaded; field_2; @ThisValue)
@If(@IsDocBeingLoaded; field_3; @ThisValue)

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:

@SetField("field_1"; field_1_OnOpen);
@SetField("field_2"; field_2_OnOpen);
@SetField("field_3"; field_3_OnOpen);

This is an elegant way to handle a fairly common scenario when using embedded editors.


Kaj said...

A SaveOptions field with the value of "0" will probably also do the trick here.

Anonymous said...


Different problem but also with embedded editors.

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 again
Hit an action.
Everything works every time.

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


Going nuts. Have posted at LDD in the 6/7 forum also.

TIA for any hints.

Doug F

Anonymous said...

I may be onto something.
If I move the code out of the form actions and into form buttons, the code seems to execute just fine.

I'd prefer to keep the action buttons since I can cascade them - anything I can do?

Doug F

Anonymous said...

Nope - moving the code to buttons on the form doesn't help.

Doug F

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.

Anonymous said...

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.

If I figure out a fix, I'll be back...


Anonymous said...

OK, last post. Any guidance or suggestions are appreciated.

Rather than repost the whole thing here, I've summarized the problem and my workaround at LDD:



Anonymous said...

OK, not last post...just saw that my
url slerbed off the screen...