Accidently leaving a page, how to delete an object created in that page.

Hi guys,   I would like to know if there is a way of deleting an object when a person leaves a page.   For example, if a user creates an order, the order is committed to the database before proceeding.  if however the user accidently clicks another link, how do i then delete that object? I currently am committing it because its helping me with other stuff. is there perhaps a way ?   Regards, Mo
1 answers

Hi Mo,

My main advice would be to restructure the app so that the commit is done when all information is available. This can for example be done by using a (non-persistent) staging entity for the intake page. Suppose you have (or add) an autonumber attribute to one of the temp committed entities. Even if you delete the object later, the number will be 'used' and a gap in the order numbering might exist..

However, there are some tricks you can use:
-The easiest way would be to define a scheduled event to delete the ghost/draft objects. Upon the 'temporary' initial commit you could set a boolean indicator. When the actual "submit order" is done by the user you can remove the indicator so it won't be deleted any more. Be sure to only delete ghost objects older than x hours (e.g 24) to prevent deletion of objects that are still being worked on. 

Note: Besides actual deletion you could also mark them with a specific status like "Deleted"/"Cancelled" to remove them from other flows.

-Using same boolean indicator, you can display any unsubmitted draft objects to the user in a special page. This could even aid to the user experience; even if the user moves away from the page by accident their data is not lost..

-Using Javascript tricks like the beforeunload event handler is not recommended (for example in the event that a user's computer crashes or loses power, the event is never fired)