Auto-Save a Record After Timeout

by Eric Wikman on October 14, 2009

3 minute read

One of our clients has a module that has many fields of data on it and they require that form to be automatically saved after a period of time.

There are several ways that we can accomplish this goal but we wanted to tread lightly and add only a minimal amount of code and not alter any of the existing logic of SugarCRM.  What we decided to do was to use a JavaScript solution that is 100% upgrade safe.

When a user is on the edit view for the module a timer is constantly running.  It is a 4 minute countdown timer.  If the user has any activity, like they click anywhere on the page or they hit any key on the keyboard, then the timer is reset back to 4 minutes and begins counting down again.  If 4 minutes elapse without them having any activity then a big bold warning message appears to notify them that the page will be saved if there is no activity within a minute.  If the user does anything in that minute then the timer resets to 4 minutes and the process starts over, but if they do not have any activity during that last minute then the page will be submitted and then the same record is reopened in edit view once again.

The warning message will always appear in the top right hand of the screen (regardless of where the user is scrolled to on the page) so it is easy to see.  The main drawback is that when the page reloads in edit view the cursor will not necessarily be in the same place it was before it was saved, but after such a long timeout there is a good chance that the user is not actually sitting at the keyboard, and the main goal is to be sure that the edits they have made are saved.  Since no logic was altered of the core code of Sugar we can be sure that we are not opening up any backdoors to edit fields that a user doesn't have access to and we maintain preexisting logic like required fields that must be filled out to actually save the form. This is what the warning message looks like:

Warning message

Contact us if you're interested in us implementing an auto-save on your instance of SugarCRM.

Get instant updates
in your inbox

Sign up and be the first to know when we publish a new article on our blog. Read our privacy policy.