S
tandard JavaScript provides 3 different types of popup boxes: Alert box, Confirm box, and Prompt box. Since Service-now.com 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 Service-now 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.
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…

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.
var priority = g_form.getValue('priority');
if (priority == 1)
return confirm('Submit a priority one ticket?');
}

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.
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;
}
}

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 ‘g_form’ API doc on the ServiceNow wiki.
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');
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.

Comments
Posted On
Oct 26, 2011Posted By
Andrew SmithHi, is there any way you can change the font colour or font size on an alert?
Thanks
Posted On
Oct 26, 2011Posted By
Mark StangerUnfortunately, JavaScript limits you in this respect. You can only control the type of alert box and arrange your text into multiple lines if needed. For more flexibility you should consider a GlideDialogWindow or a g_form info message. I’ve updated this page with more information on these options.