I’ve used an `.addButton` on my form, and then pri...
# suitescript
d
I’ve used an
.addButton
on my form, and then printed the output of the function as time goes on by appending to innerHTML. On Firefox, this works fine. On Chrome, the page completely freezes until the function is complete, and then suddenly all the output displays. I’m using mostly
nlapiLoadSearch
which I think is render-blocking - is there any way around this?
n
Can you post some function code
d
here’s a very cut down version
Copy code
SS code: form.addButton('custpage_newdl', 'Download', 'getPricelistItems()');

CS Code:
function getPricelistItems() {
    var diff;
    var f;
    document.getElementById("div__body").innerHTML += "<br />"+'(1/6) Loading pricelist...';
    var reportChoice = nlapiGetFieldValue('custpage_report');
    var priceChoice = nlapiGetFieldText('custpage_price_level');
    var customerChoice = nlapiGetFieldValue('custpage_customer');
    reportChoice = pListIds[reportChoice];
    var search = nlapiLoadSearch('customrecord_price_list_items', 'customsearch_price_list_items');
    var filter = new nlobjSearchFilter('custrecord_pli_price_list', null, 'anyof', reportChoice);
    var columns = search.getColumns();

    search.addFilter(filter);
    var results = search.runSearch().getResults(0, 1000);
    if(results) {
      if (results.length === 1000) { results = searchMore(search, results); }


      var priceListProducts = [];
      var priceListOrder = [];

      if (results && results.length > 0) {
          for (i; i < results.length; i += 1) {
              if(results[i].getValue(columns[2])!='T') { //Column 2 ('header') should be false
                priceListProducts.push(results[i].getValue(columns[1]));
              }
              priceListOrder.push({'code':results[i].getValue(columns[1])});
          }
      }
  }
}
the “(1/6) Loading pricelist...” displays fine on Firefox, but only appears after either the function crashes, or the function completes - it seems it just render blocks on Chrome either at search, or on the ‘add button’ function call
n
The render/blocking of page is understandable as Javascript engines treats functions as Objects, so they most engines necessarily execute them first and then treat the result as a object.
I think you should do the rest of your stuff (apart from '(1/6) Loading pricelist...' ) in a ajax call or using a promise function.
If that doesn't work, you should create a restlet and call it. That is something tried and tested. When we have some Suitelets that update bulk Data, We 1.) Push the data into an array that needs to be updated. 2.) change the div__body to 'Please Wait'. 3.) Send over the collected data array to a restlet which returns either success or the failure with the records that failed.
d
right okay, i was trying to keep it the same function but that does make sense.. thank you @Nik!