Hi, I am trying to populate an html on my suitelet...
# suitescript
t
Hi, I am trying to populate an html on my suitelet using data from saved search. At first I was successful using array. But I figure out I cannot use array if I am about to display hundreds of records. Can someone help me on showing how can I loop my data then display it on the html data table. Thank you keanu thanks
e
You'll probably need to share the code you're using and/or the data structure you need to loop over
t
On my Suitelet, I have the search, then I try to populate the HTML by passing the array and manually declaring the array index.
Here is what my SL look like
I want to achieve a dynamic populate of table row, whereas, I don't need to declare the index of my array
e
Been a long time since I've had to write SS1.0 or ES5.1, but it's not clear to me why you can't iterate over
data
.
Copy code
function toTable(data) {
  var html = '<table><thead>...</thead><tbody>';

  for (var i = 0; i < data.length; i++) {
    html += [
      '<tr>',
      '<td>' + data[i].account + '</td>',
      '<td>' + data[i].type + '</td>',
      '</tr>'
    ].join('');
  }

  html += '</tbody></table>';
  return html;
}
I'm just guessing at what the surrounding
<table>
looks like, and I stripped out all the styling for readability; you could extract all the inline styles to a
<style>
tag elsewhere in the document
😅 1
keanu thanks 1
t
Thanks now I get this, I think the reason I am having a hard time, because there is already an existing html. It's kinda difficult to inject the dynamic since everything on the existing html data are hard coded. Thank you @erictgrubaugh for taking time on writing the code. I will use it as my starting code :)