I have a client script that takes a bit to complet...
# suitescript
p
I have a client script that takes a bit to complete so wanted to add a throbber and found a great tutorial on a blog that does this via a DOM manipulation. My problem is I am not sure where exactly to put the destroy part of the jquery so that the spinner stops once the script is complete. This is what I have now:
Copy code
function selectOption(context) {
        var options = {
            title: 'Select Option',
            message: 'Select your option.',
            buttons: [{
                    label: 'Option 1',
                    value: 1
                },
                {
                    label: 'Option 2',
                    value: 2
                }
            ]
        };

        function success(result) {

            
            var rec = currentRecord.get();
            if (result == 1) {
                    jQuery('#_loading_dialog').attr('title', 'Running Automation');
                    jQuery('#_loading_dialog').html( "<div style='text-align:center; font-style: italic;'>Please Wait</div><br><br><div style='text-align: center; width:100%;'><i class='fas fa-cog fa-spin' data=fa-transform='grow-18'></i></div>" );
                    jQuery('#_loading_dialog').dialog({
                        modal: true,
                        width: 400,
                        height: 160,
                        resizable: false,
                        closeOnEscape: false,
                        position: { my: "top", at: "top+160", of: '#main_form' },
                        open: function (evt, ui) {
                            // jQuery(".ui-dialog-titlebar-close").hide();
                            setTimeout(function(){ 
                               // My Code Here
                            }, 100);
                        }
                    });
                    jQuery('#_loading_dialog').dialog('destroy');
                }
            if (result == 2) {
                // My Code Here
            }
        }
        function failure(reason) {
            console.log('Failure: ' + reason)
        }
        dialog.create(options).then(success).catch(failure);
    }
Where should I put the
jQuery('#_loading_dialog').dialog('destroy');
s
Hard to be sure without some better context of what exactly exactly happens in //My Code Here, but you probably want to call the destroy on success of whatever is in there
p
Makes sense. So the code is adding different items to a sales order depending on what option is chose. there is also some currency conversion and custom calculations before the items are populated. Last part of that code is the .commitline of the items.