Feature Coverage: Confirmation when navigating away in a Record Producer

The Fruition Partners team faced yet another customization issue. 😉 or to put it in other words: how to help not losing your information while multitasking if you mistakenly navigate away from a page?

Record Producers are a very convenient way to ask users to fill-in a form. They offer many possibilities: among them, the possibility to display explanations for each field, make fields mandatory or read-only, and even script the behaviour of the information to be entered (e.g.: a field becomes visible only when a specific value is selected in a drop-down list). However, it can be very frustrating to spend a lot of time filling a Record Producer, and navigating mistakenly away from the page causing the loss of all the information you just seized.

The solution Fruition Partners came up with, was to create a script that displays a confirmation message to the user. If  s/he tries to navigate away from the Record Producer and some modifications have not been submitted yet, the script runs and the confirmation message appears drawing attention to what you are about to do (or loose).

It can be easily used in multiple Record Producers (no code duplication) and is smart enough to let the administrator decide which fields are important and should be checked when leaving the page.


The gain: No more fear of losing data (and time)! When the user tries to navigate away from the page (typically when clicking by mistake on some link), s/he will get a confirmation message and have the possibility to stay on the page, and therefore submit the record (exactly as in a standard Service-now.com form when the “glide.ui.dirty.form_support” System Property is enabled).

Simply powerful!



Here is an example of Catalog Client Script to achieve the check described in the article above. Please note that each Variable of the Catalog Item/Record Producer must be checked individually (the example below has three Variables; each “<variableX>” tag must be replaced by the real Variable name).



 * Adds a confirmation message when exiting the Catalog

 * Item or Record Producer with unsaved modifications.


function onLoad() {

   var u_g_form_dirty = false;

   window.onbeforeunload = function () {

      // All variables of the Record Producer must be checked individually

      if(g_form.getValue(“<variable1>”) != “”) {

         u_g_form_dirty = true;

      } else if(g_form.getValue(“<variable2>”) != “”) {

         u_g_form_dirty = true;

      } else if(g_form.getValue(“<variable3>”) != “”) {

         u_g_form_dirty = true;

      } else {

         u_g_form_dirty = false;


     // Message that will be displayed to the user. Can be left blank.

     var warningMessage = “CUSTOM TEXT: You will lose all unsaved changes!”;

      if(u_g_form_dirty) {


      } else {





    Recommended Posts

    Leave a Comment

    Start typing and press Enter to search