How to Autosave form every 5 seconds while typing short description.

Hari haran
Tera Guru

This Onload Client script autosaves the form(record) every 5 seconds while typing short description.

 

function onLoad() {
//Use the 'onkeyup' event to check the 'isMaxLength' function
//Get the control
var control = g_form.getControl('short_description');
//Set its onkeyup method
control.onkeyup = isMaxLength;
}

function isMaxLength() {
var mLength = g_form.getValue('short_description');
var control = g_form.getControl('short_description');
if (control.value.length != mLength) {
setTimeout(function() {
g_form.save();
}, 5000);
g_form.addInfoMessage("working");
//control.value = control.value.substring(0, mLength);
} else {
g_form.addInfoMessage(" not working");
}
}

 

1 REPLY 1

Tony Chatfield1
Kilo Patron

Hi, unless I misunderstand this script saves the record every 5 seconds if you are adding a short description;
So it will fail if mandatory fields are not populated and will also potentially insert the record before you have finished populating all fields, unless a very exact process is followed.
The result of this early insert may be business rules that do not run on insert as fields are not populated\conditions are not met, or BR's that run multiple times unnecessarily as you populate empty fields.
In addition, the short description population may take multiple 'saves' which consumes system resource for no reason and depending on configuration may result in notifications with incomplete short descriptions and assorted other unexpected behavior.

 

Sorry, but I cannot think of a situation where this type of 'solution' would be best practice and would not recommend anyone consider implementing it.