Loading Image for the Background process

Loading image that has to show while an action works on the background.

Promise is used to show the loading image and background action concurrently.

The script part shows is from the client script. On the Button Click action of the User Event, we are triggering this script part it will show a confirmation box. If we confirm as YES the action will take place else nothing happens. On the success, we will automatically reload that respective page.

createRma: function () {
                var r = confirm("Create RMA for this Order?")
                if (r == true) {
                    var deliverOrder = currentRecord.get().id;
                    var parameterObj = {
                        doId: deliverOrder
                    };
                    var promise = new Promise(function (resolve, reject) {
                        jQuery("#custbody_jj_loding_image").css("display", "block");
                        setTimeout(function () {
                            resolve();
                        }, 500)
                    });

                    promise.then(function () {
                        var rmaUrl = url.resolveScript({
                            scriptId: "customscript_jj_rma_creation",
                            deploymentId: "customdeploy_jj_rma_creation",
                            returnExternalUrl: false,
                            params: parameterObj
                        });
                        var response = https.get({
                            url: rmaUrl
                        });
                        if (response.code == 200) {
                            window.location.reload();
                        } else {
                            alert("RMA is not created because of some issues.")
                        }
                    }).catch(function (errr) {
                        console.log('errr', errr);
                    });
                }
            },

Leave a comment

Your email address will not be published. Required fields are marked *