logo

NJP

Developer Utility — SaveNow

Import · Jun 08, 2016 · article
  1. /*
  2. Add Event Listener on key down event for CTRL+S
  3. */
  4. document.addEventListener("keydown", function(event) {
  5. //keycode 83 is for s
  6. //identify main key ==> metakey || ctrlkey
  7. if ((window.navigator.platform.toUpperCase().indexOf('MAC')>=0 ? event.metaKey : event.ctrlKey)   && event.keyCode == 83) {
  8. //Get the event value, "event.which" is for FF
  9. event=event||window.event||event.which;
  10. //Prevent the dafault function called by CTRL+S
  11. event.preventDefault();
  12. //Get full element of the form
  13. var _form=g_form.getFormElement();
  14. //Get the sys_id value from the URL to check which UI Action needs to be called
  15. var _sys=getParameterFromURL("sys_id").toString();
  16. //Based on value of sys_id, we will decide that which UI Action needs to be called, either for insert or Update
  17. var _btnAction=_sys=="-1"?"sysverb_insert_and_stay":"sysverb_update_and_stay";
  18. //call the UI Action
  19. gsftSubmit(null, _form, _btnAction);
  20. }
  21. }, false);

You can also copy this code form github repository or download the UpdateSet from github.

Let us know, IF you are facing any issue while using this UpdateSet.

To read more such interesting posts. Click here

----

visit www.inMorphis.com/blogs/ for more

View original source

https://www.servicenow.com/community/north-texas-snug/developer-utility-savenow/ba-p/2286192