RE: How to Add a Client Script Progress Bar
Hi, does anyone have any tips on how to add a progress bar to a client script? Basically, when a button is clicked on the form, it triggers code that takes a while. I just need a progress bar to indicate the script is still running. It doesn’t even need to show an exact percentage of completion, just something to show it’s running.
I like the javascript approach. Use your favored javascript library to show a progress bar / loader. Since I still had it setup in a test account , here is an example using Sweet Alert 2 (https://sweetalert2.github.io/). Sweet Alert 2 isn’t a progress bar library, but it can be abused to do so.
/**
* @NApiVersion 2.x
*/
define(["./sweetalert2.all.js", "N/https"], function(Swal, https) {
return {
button: function() {
Swal.fire({
onBeforeOpen: Swal.showLoading,
onOpen: function() {
https.get
.promise({
url:
"https://www.example.com"
})
.then(
function() {
Swal.close();
},
function() {
Swal.hideLoading();
Swal.update({ type: "error", text: "An error occured" });
}
);
},
allowOutsideClick: false,
allowEscapeKey: true,
text: "I'm busy"
});
}
};
});
I added the above as a button function’s code using a beforeLoad user event script to avoid NetSuite trying to run sweetalert2 serverside.
Thanks for the example!