Creating new rows & using the new unsaved changes warning

I’m trying to update some of my pages to use the new page option “Warn users if page has unsaved changes”, but am running into some issues. On my opportunity page, I have a field editor that lets the user create a task for the purpose of logging a call at the same time as updating an opportunity. Our current business rules are that a user is only going to update an opportunity if they have spoken to the customer on the phone.

However, when I enable the option “Warn users if page has unsaved changes”, it warns me about unsaved changes when I try to leave the page, even if I haven’t touched anything; that is, if I open an opportunity and then immediately try to leave the page, the warning pops up. As best as I can tell, this is because I have the task model creating a new row on page load.

Are there any guidelines/tutorials on how to use the new unsaved changes warning in conjunction with creating new rows (that may or may not be utilized)? I have a few other pages that create new rows in popups (and I’m guessing I’ll run into some issues there too), etc and want to make sure I’m approaching this the correct way.

Jonathan, great question, very valid point. Fortunately I was working through this very scenario today, so I think I’ve got some guidelines that will help you out.

The recommended approach would be to move to using the Action Framework to show your Popup. That way you can have an Action sequence that takes care of creating a default row in your “New record” Model, as needed. Then, you can turn OFF the “Create default row in Model if Model has none” property on the Model, and have an Action Sequence that does the following:

  1. Cancel Models: [] — this throws out any changes that may be hanging around for some reason.
  2. Create new row in Model:
  3. Show Popup

In the Popup, you have a “Save” button that will Save your new record, maybe requery the main Table’s Model, and then Close the Popup when a successful save finishes. You also have a “Cancel” button that Cancels the New Record Model, throwing out the new record, then Closes the Popup.

If you follow an approach like this, then you shouldn’t get the unsaved changes warning on account of your New record models having unused rows in them.

Zach, that sounds great! However, what if the user clicks the ‘X’ on the popup or hits ‘esc’ on the keyboard? Both of these seem to close the popup but do not appear to fire the ‘cancel’ function on the model… or am I going crazy?

No you’re not crazy, that is a loophole right now which we need to address. We’re considering adding “After Close Actions” that would be run whenever the popup is closed, whether it is closed by the user hitting ESC, clicking the “X”, or clicking a “Close” button that calls the Action Framework’s “Close [All | Topmost] Popup[s]” action. That should take care of this scenario.

In the meantime, this is one of the reasons it’s important to have the “Cancel Models” run before showing the popup — to try to clear out new rows that were created but which weren’t cleared because the user hit ESC or clicked X.

Ok, great - glad to know I wasn’t just missing something. It’d be great to eventually get that loophole addressed, but it seems like it’s fairly easy to work around it for now.

Thanks again or the help!

Just wanted to post a quick update here for anyone following along. It’s been a while, but we do now officially support After Close Actions for our popups! You can add these under Popup Properties in the composer: 

See this documentation for more info: