SweetAlert - a beautiful replacement for javascript's "alert"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2015 10:50 AM
SweetAlerts2 is out.
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!.
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.
- Labels:
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2018 08:23 AM
Try this example. Change wording/options to required:
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonClass: "btn-danger",
confirmButtonText: "Yes, delete it!",
cancelButtonText: "No, cancel plx!",
closeOnConfirm: false,
closeOnCancel: false
},
function(isConfirm) {
if (isConfirm) {
swal("Deleted!", "Your imaginary file has been deleted.", "success");
} else {
swal("Cancelled", "Your imaginary file is safe :)", "error");
}
});
Regards
Paul

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2018 08:40 AM
It doesn't seem to reach the function(isConfirm) in your example. Does it work for you?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2018 08:59 AM
Hi,
Just to confirm. Are you using SweetAlert or SweetAlert2?
Regards
Paul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2018 09:16 AM
Actual code below (SweetAlert 1 example) tested in Jakarta as working with SweetAlert (Not 2), isConfirm options work as expected.
If you are using SweetAlert 2 then look here: https://sweetalert.js.org/guides/ at the section 'Upgrading from 1.x" The most important change is that callback functions have been deprecated in favour of promises i.e. you should be using .then((value) { rather than function(isConfirm) {if (isConfirm) { etc
SweetAlert 2 Question/Response Example:
function testit() {
SweetAlert 1 Question/Response Example:
function testit() {
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonClass: "btn-danger",
confirmButtonText: "Yes, delete it!",
cancelButtonText: "No, cancel plx!",
closeOnConfirm: false,
closeOnCancel: false
},
function(isConfirm) {
if (isConfirm) {
swal("Deleted!", "Your imaginary file has been deleted.", "success");
} else {
swal("Cancelled", "Your imaginary file is safe :)", "error");
}
});
}
Regards
Paul

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2018 09:49 AM
It does seem like an issue with SweetAlert 2 since they switched to promises. ServiceNow doesn't seem to support the => method.
I searched around and found user, geni, said promise was possible in SN: https://community.servicenow.com/community?id=community_question&sys_id=c83683a1db1cdbc01dcaf3231f9619e4&view_source=searchResult
I just see how his rough example would be adapted for SA2.