Auto-Save a Record After Timeout

sugarcrmdevelopers —  January 14, 2011

Editors Note: This is another post syndicated from the Epicom company blog. Epicom is one of our largest North American partners, and this post illustrates the ingenuity of their engineering team. Here they show an upgrade-safe way to have a record be automatically saved after a period of time.

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:

Auto-Save

Give us a call if you’re interested in us implementing an auto-save on your instance of SugarCRM.