Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Michael-PHL
Tera Guru

Is there any examples of using SweetAlert in Catalog Client Scripts (Currently on CMS but moving to portal in the next few months).  This is just a test script below as we want to use it is a confirmation on specific items that they included certain information before proceeding.  No matter what I try, the pop-up stays on the screen for a quick second and then goes to the confirmation page (checkout).   This is using an onSubmit

 

function onSubmit() {
  swal({
  title: 'Are you sure?',
  text: "You won't be able to revert this!",
  type: 'warning',
  showCancelButton: true,
  confirmButtonColor: '#3085d6',
  cancelButtonColor: '#d33',
  confirmButtonText: 'Yes - Submit!'
}).then(function(result) {
  if (result) {
	return true;
  } else {
	return false;
  }
});
	 
}

I am having the same exact problem. I tried something almost identical to this and the pop-up vanishes within a couple seconds, instead of waiting for the "Confirm" button to be clicked.

same here, i played around and changed it to an onChange as that would be the only way the message stays up for long enough for someone to read it. 

 

Jose Baby1
Tera Contributor

Hi ,

The below snippet is from an on submit catalogue client script , but the browser does not wait for the user response and continues to execute the rest of the code . Is there a way to pause the execution until the sweet alert gets a response from the user ?

Thank you 

Jose

swal({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes - Submit!'
}).then(function(result) {
if (result) {
return true;
} else {
return false;
}
});

Michael-PHL
Tera Guru

Wondering if anyone found an answer to the onSubmit question yet.