AlertNow - Share - JavaScript Alert Replacement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2016 06:49 AM
I must say that I was highly impressed by sweet alert (which you can find here: ServiceNow Share ), which is amazing. I've always been bothered by just how bad the default JavaScript alert dialogs look compared to ServiceNow's actual UI. I wanted to introduce something similar, but without the need for importing a 3rd party library. As such, I created AlertNow, which is a wrapper for a native ServiceNow replacement for JavaScript's alert functionality. It uses a UI Page combined with ServiceNow's GlideModal class to elevate the user experience by replacing JavaScript's basic 'alert' functionality.
alertNow is a modular alert that is powered by ServiceNow's GlideModal class. There are several potential use cases:
1. Allows you to relay information to the user with a simple, attractive and configurable modal dialog based on a standard format.
2. Allows you to specify a URL for a server-side redirect after the dialog is closed, if desired.
How do I install it?
All you have to do is deploy the Update Set. After that, you can call AlertNow from any client-side script in the system.
How do I use it?
The parameters for AlertNow are easy - just pass it a native JavaScript object with some or all of the following properties:
You can provide either message or propName, but not both.
message - This is the content of the message body. Only plain text is allowed.
OR
propName - This parameter must contain the name of a sys_properties record in which you can specify a message. Use this if you would like to standardize your message using properties, or if you want to render HTML in your modal dialog, such as URLs. You can also specify additional styling in the property.
You may configure the font size of the main message with the following parameter:
fontSize - acceptable values are:
small
medium
large
x-large
Medium is the default size.
title - The title will display in the upper-left corner of the modal window.
header - This is the header that will display above the message body.
headerSize - You may specify the size of the header by passing one of the following values:
small
medium
large
Large is the default size.
image - An optional image to display above all text content. Simply pass the image URL. The size is based on the image's actual size by default.
imageWidth - allows you to specify the width of your image as a number.
imageHeight - allows you to specify the height of your image as a number.
url - An optional redirect URL. If present, the form will display both 'Ok' and 'Cancel' buttons. 'Cancel' will close the dialog, while 'Ok' will execute a redirect to your specified URL (server-side).
You may also omit either the cancel or OK buttons with the following parameters:
showCancel - boolean - true to show, false to hide. The default is true.
showOk - boolean - true to show, false to hide. The default is true.
You may call this alert from any client-side script in the system using:
alertNow(yourObject);
You can find AlertNow here: ServiceNow Share
Script examples:
alertNow({url: 'stats.do', message:'You must assign this task and update its Work notes before closing it.', header:'Task Not Closed', title:'My Title', image:'warning-shield.png'});
********************
alertNow({title:'Congratulations', header: 'Great Job!', message: 'Fantastic work. You submitted that form perfectly.', image: 'http://images.techtimes.com/data/images/full/163416/meaning-of-vault-boy-thumbs-up-jpg.jpg?w=600', imageHeight: '400', imageWidth: '200'});
********************
var myProperty = however you get properties via GlideAjax;
alertNow({propName: myProperty, header:'Contract Required', title:'My Title'});
Visual samples:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2016 02:48 PM
Update: v2.0 is now available
**************** - New with v2.0 - *****************
"hideClose":
- Allows you to hide the 'X' that appears in the top-right of the modal window.
- True to hide, false to show.
- Defaults to false.
"video":
- Allows you to embed a YouTube Video into your AlertNow messages.
- Simply pass the video's embed URL using this parameter.
- Note: The 'X' will always appear in the top-right corner when a video is present - and no buttons will be displayed underneath it.
I also changed the formatting slightly - there is now more white-space between the body elements and the UI Buttons.
Script example:
alertNow({title: 'Embedded Video', header:'Now with Video!', message: 'You can now embed YouTube videos in your alertNow messages.', video: 'https://www.youtube.com/embed/DCEBsuXmBrM'});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2016 07:13 AM
Andrew,
Is there any more documentation on this with basic and advanced examples? We just implemented SN in December of last year and most of us are still building our skills with the product.
Thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2016 08:26 AM
When using a normal JavaScript alert I am capturing the answer to that whether it be clicking the OK button which would return true or clicking cancel.
My line looks like this:
var answer = alertNow({message:msg, header:'Ready for Deployment', title:'Deployment Confirmation', headerSize:'medium', hideClose: true, showCancel: true});
I have a variable called msg that has the actual text and that's working. The hideClose is working. The showCancel is not working. I got that by looking at the XML file. Don't know if I have that parameter identified correctly or not. After clicking OK in the regular JavaScript alert, I can capture the return of True and act accordingly. The same alertNow functionality is not working the same. Does anyone have an example of how to use this to capture the actual clicking of the buttons? Love the look of the alertNow dialog boxes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2016 08:46 AM
Hi Stanley,
Are you using the JavaScript 'confirm' functionality (Window confirm() Method)? If so, that's something I'm currently working on at the moment. Currently, alertNow only recreates the functionality of a basic alert (albeit with the addition of a potential redirect).
As for the 'showCancel' parameter - it works, but not without the 'url' parameter. When the 'url' parameter is present, both the Cancel and Ok buttons are displayed by default. Ok will commit a redirect to the URL you pass in on the 'url' parm, while cancel will simply close the dialog.
Without the 'url' parameter, you only have the option to display Ok.
Wow, that sounds pretty cryptic .
I'm working on additional documentation complete with more specific examples and screenshots. I should have that completed by this weekend (that's really the only time I can work on this stuff). I would also like to implement the 'confirm'-like functionality that you mentioned above - I think that would really round out the utility. I just have to experiment with capturing the return values from the modal.
Thanks for the feedback!