The CreatorCon Call for Content is officially open! Get started here.

SweetAlert - a beautiful replacement for javascript's "alert"

Matt Saxton - G
Kilo Guru

 

SweetAlerts2 is out. 

 

SweetAlerts2

 

Hi Dev's,

 

Last night i was working on an application that needed some input. So i used SweetAlerts on the custom UI page and it turned out really nice looking, and i thought i could use globally!.

 

ServiceNow Share - SweetAlert

 

Once you install you can do any of the tests via the console

 

parent.swal({     title: "Are you sure?",     text: "You will not be able to recover this imaginary file!",     type: "warning",     showCancelButton: true,     confirmButtonColor: "#DD6B55",     confirmButtonText: "Yes, delete it!",     closeOnConfirm: false }, function(){     swal("Deleted!", "Your imaginary file has been deleted.", "success"); });

 

Make sure that you use "parent.swal()"

 

Here's more examples listed here SweetAlert

 

Screenshot's below.

 

2015-10-01 13_48_38-ServiceNow.png

 

2015-10-01 13_37_06-ServiceNow.png

44 REPLIES 44

matthew_magee1
Giga Guru

Hey Matt.



2 things:



  1. I can get the script to run using Fuji, however, when I try to run it in Geneva, nothing happens. Here is the error I'm getting in the UI script:
    Snap1.jpg
  2. How can i get this alert to show up on a group of user's SN instances instead of just the client calling the script? We have an operations center w/ 10 ppl or so. They'd like to get an alert on their screen when a new critical ticket comes in


Thanks!


Elienai Figueir
Giga Contributor

Hey Matt,



I saw if there is a new version of SweetAlert on internet: https://limonte.github.io/sweetalert2/#select-box



Can you create the xml file to install on the ServiceNow?



Thanks


Hello Everyone



I have checked this feature and looks awesome. I have small question in using this. Can we also pass a URL link using this swal(). I know URL's/links are not supported by alert() method. But just curious if this is possible. Below is what I'm looking for.


find_real_file.png


I would like to see the text as well as the link(Click here).   I know this is not usually supported by alerrt(). Any thoughts on this is greatly appreciated.



Regards!


Hello Surya



Thanks for responding. I was able to use the swal(), but unfortunately the link is not populated on the alert, I can see the text message, confirm button but the url is not displayed. I have just used the code which was there in the above link you have given. Please find my code I'm using and the output I see



Catalog Client Script:


function onChange(control, oldValue, newValue, isLoading) {


//debugger;


//alert('testing');


if (isLoading || newValue == '') {


return;


}


var x = g_form.getValue('computer');



if(x == 'mac')


{


/*alert("This is test <a href='www.google.com'>Google</a>");


var dialog = new GlideDialogWindow('alertpopup');


dialog.setTitle("Please Check Macbook instructions");


dialog.setSize(500,200);


dialog.render();*/



swal({


title:'We are pleased to offer Macs with "best effort" support.   For more information before making the switch to a mac, please click here to ensure you understand the support that will be available to you',


html:'<a href="//google.com" target = "_blank">Click here</a>',


confirmButtonText: 'Ok',



});




}


}



Below is the output I see:


find_real_file.png



LINK IS NOT DISPLAYED IN THE ABOVE ALERT. Please let me know if I need to tweak something in the code?



Regards!