Standard JavaScript provides 3 different types of popup boxes:  Alert box, Confirm box, and Prompt box.  Since ServiceNow supports standard JavaScript, these popup boxes can be used anywhere in the application where client-side JavaScript is supported.  They will most commonly be used in an ‘onSubmit’ client script or a UI action with the ‘Client’ checkbox checked.  Below are some examples of how each of these popups could be used within the context of a ServiceNow implementation.

Alert Box

An alert box is often used if you want to make sure information comes through to the user.  When an alert box pops up, the user will have to click “OK” to proceed.

This script could be used in an ‘onChange’ client script on the Incident table to alert the user of a change to the ‘Priority’ field.

function onChange(control, oldValue, newValue, isLoading) {
    if (!isLoading)
    alert('You changed priority from ' + oldValue + ' to ' + newValue);
}

If you had a longer message in your alert box, you could make the message a multi-line message like this…

alert('You changed the priority from ' + '\n' + oldValue + ' to ' + newValue + '\n' + 'Longer message text...');


Javascript Alert Popup

Confirm Box

A confirm box is often used if you want the user to verify or accept something.  When a confirm box pops up, the user will have to click either “OK” or “Cancel” to proceed.  If the user clicks “OK”, the box returns true. If the user clicks “Cancel”, the box returns false.

This script could be used in an ‘onSubmit’ client script to ask the user if they really wanted to proceed with the record submission.

function onSubmit() {
   var priority = g_form.getValue('priority');
   if (priority == 1)
      return confirm('Submit a priority one ticket?');
}


JavaScript Confirm Popup

Prompt Box

A prompt box is often used if you want the user to input a value before continuing with an action.  When a prompt box pops up, the user will have to click either “OK” or “Cancel” to proceed after entering an input value.  If the user clicks “OK” the box returns the input value. If the user clicks “Cancel” the box returns null.

This script could be used in a client-side UI action on the Incident table. Make sure that you check the ‘Client’ checkbox and add ‘promptUser()’ (or whatever your function name is called) in the ‘OnClick’ field of your UI action.

function promptUser(){
   var con = prompt("This is really dangerous. \nType 'Continue' if you really want to perform this action.");
   if(con == 'Continue'){
      g_form.setValue('comments', 'Dangerous action performed.');
      gsftSubmit(gel('sysverb_update_and_stay'));
      //gsftSubmit(gel('sysverb_update'));
   }
   else{
      return false;
   }
}


JavaScript Prompt Popup

Additional Alert/Info/Error Message Options

Each of the methods above use standard JavaScript. They’re quick and simple, but sometimes they don’t provide all of the flexibility you need. For example, you can’t change the formatting of text other than to add line breaks in text strings.

ServiceNow provides some other options that you can consider however…

g_form Form and Field messages

I like using form and field messages in place of alerts sometimes because I think it gives a cleaner look than an alert popup. These are very easy to use and, in the case of form messages, support any HTML you want to throw into them. Here’s a quick example, you can view the full messages cheat sheet here.

//Form header info and error messages
g_form.addInfoMessage('<font color="green">addInfoMessage (Green)</font>');
g_form.addErrorMessage('<b>addErrorMessage (Bold)</b>');

//Field info and error messages
g_form.showFieldMsg('caller_id', 'showFieldMsg Info Message', 'info');
g_form.showFieldMsg('caller_id', 'showFieldMsg Error Message', 'error');

Client-side Info and Error Messages

GlideDialog Popup Windows

I’ve written quite a bit of information on some of the cool things you can do with GlideDialog Windows. These allow for pretty much all the functionality you can dream up, but that does come with whatever complexity is required to produce the solution. GlideDialog isn’t going to be a good replacement for standard JavaScript popups, but they might fit the bill when you’ve got a more complex requirement.