Auto save request (save like draft)

inish
Kilo Contributor

Does servicenow has any auto save functionality.

the form would automatically save periodically to prevent loss of information if the requester is away from his/her desk.

any thoughts?

10 REPLIES 10

xiaix
Tera Guru

I have this auto-save feature on several of my custom UI Pages... but adding it directly to a "Request" I'm not sure.   Would you like me to show you how my UI Page auto-save works?


inish
Kilo Contributor

Yes please.


First, I set a JavaScript variable on my UI Page:



var record_sysID = "${gr.sys_id}";


var refreshIntervalId = setInterval(autoSave, 600000); <!-- 10 minutes -->



Next, in my Client Script, I declare the "autoSave" function



function autoSave()


{


  var ga = new GlideAjax('autoSave_myForm');


  ga.addParam('sysparm_name', 'autoSave_myForm');


  ga.addParam('sysparm_RecordSysID', record_sysID);


  ga.getXMLWait();


  var answer = ga.getAnswer();



  if (answer > 0)


  alert("autoSaved!");


  else


  alert("autoSaved did not work!");


}



The Script Include: autoSave_myForm



var autoSave_myForm = Class.create();


autoSave_myForm.prototype = Object.extendsObject(AbstractAjaxProcessor, {


autoSave_myForm: function() {



  var RecordSysID = this.getParameter('sysparm_RecordSysID');


      var gr = new GlideRecord('my_table');


      gr.addQuery('sys_id', RecordSysID);


      gr.query();



  var answer = 0;



  if (gr.next())


      {


              gr.update();


              answer = 1;


      }



  return answer;


}


});




Just to note, I'm getting "${gr.sys_id}" from   g:evaluate code on the UI page, but since you're not working from a UI page, you could use "current.sys_id".  



Again, to stress, this works from within a UI Page, and probably will not work for how you're wanting to use it.   You said you'd like to see how I did it on a UI Page though, so I'm honoring that request.


Brad Tilton
ServiceNow Employee
ServiceNow Employee

I think the answer is no, there isn't anything like this oob. If you're talking about incident and change request type forms you could probably do some auto saving with a custom client script.