Saving unsaved changes using uQueryCanDeactivate or uQueryCanClose


In VLF-ONE filters and command handler may have a redefined uQueryCanClose method.

This is invoked when the user takes an action that would cause the filter or command handler to close.

It is passed a Boolean parameter #CanBeCancelled indicating whether it is allowed to cancel the close request.

It returns a Boolean value #Allow indicating whether the close request should be cancelled. If the close cannot be cancelled this is assumed to be true (allow the close) regardless of the actual value returned,

This means uQueryCanClose serves two purposes:


In VLF-WIN the uQueryCanDeactivate method is invoked when the end-users try to move from the command handler to somewhere else in the Framework, or when they try to close down the Framework. It is run when the user clicks on another command tab, a new instance of the business object or another business object or application.

It is particularly useful for saving unsaved changes. The routine can check whether changes need to be saved. If so, the user can be asked "Do you want to save your changes before continuing?" (Yes/No). If they answer Yes, their changes can be saved.

At the time the routine is run, the command handler still has all its values as they were before the user attempted to move away. So checking for unsaved changes, and saving those changes, is easy.

To use it, you need to set the avNotifyDeActivation property in the command handler's initialize routine

* Handle Initialization

Mthroutine Name(uInitialize) Options(*REDEFINE)

* Do any initialization defined in the ancestor

Invoke #Com_Ancestor.uInitialize

* Activate Check for unsaved changes (Unsaved changes logic)

set #Com_Owner avNotifyDeactivation(TRUE)



Then add a redefined uQueryCanDeActivate routine to your command handler:


* The Framework initiates this when the user moves to another command tab, or business object instance,  or business object, or application, or closes the Framework.

* (The Framework may initiate this method multiple times)


* Define_Map For(*Result) Class(#vf_elBool) Name(#Allow)

#Allow := True

if '(#pty_NeedsSaving *eq TRUE)'

* If something needs saving, ask the user if they want to save it

USE BUILTIN(MESSAGE_BOX_SHOW) WITH_ARGS('YESNO' 'YES' *Default *Default 'The notes have been changed. Would you like to save your changes before continuing?') TO_GET(#MSG_RET)

if '#MSG_RET *eq YES'

* Save everything

<< my save logic>>


#pty_NeedsSaving := False




A more complicated version could set #Allow to false if there was an error during the save, and in that case the user would not go to where they clicked, (or the Framework would stay open if they were attempting to close it).

Also see:

Reason Code