Autosave a screen

I had a question asked ages ago about Auto-Save of a screen. And Dan Hutson have just posted an answer to this question:

// auto-save after this many minutes
var countDown = 15; 

// get current time at screen load
var startTime = new Date(); 

// calculate one minute
var oneMinute = 1000*60; 

// run clock function every minute
var int = self.setInterval("clock()",oneMinute); 

function clock() {
    // get time now
    var timeNow = new Date(); 
    var countUp = Math.ceil((timeNow.getTime() - startTime.getTime()) / oneMinute); 
    // calculate differences in times
    // calculate time remaining until auto-save
    var minsRem = countDown - countUp; 
    // update edit box on screen with number of minutes remaining (optional)
    $HRnet("EditBox3").setDisplayValue(minsRem + " minute\(s\)"); 
    if(minsRem == 0) {
        // save screen if auto-save time has elapsed
        // reset current time
        startTime = new Date(); 

// call clock function on first load

This is all Dan’s script and it shows the countdown before every auto-save. The main function here is HRnet.Form.UI.Buttons.Save.doClick(); that does save the data, the rest of the code is count-down and displaying.

So if you don’t need any of this, you can just call HRnet.Form.UI.Buttons.Save.doClick(); whenever you need, or on timer:

$(document).ready(function() {
    window.setInterval(HRnet.Form.UI.Buttons.Save.doClick, 5000);

This would click Save button every five seconds.
I believe this would not work in a workflow, as you can’t save the workflow – you need to submit the workflow and that can happen only once. And would really you want to submit the workflow many times, when you have some complex logic behind it (i.e. send email to everybody in your company)??

Thanks for the idea, Dan!!

This entry was posted in Uncategorized and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *