0

How do you print all values in an array onto the modal dialog? I have tried the code below but it only prints the last array value.

for (var count = 0; count < 10; count++) {
  var htmlOutput = HtmlService.createHtmlOutput(arr[count]);
  var arrayOutput = SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'Test');
}
2
  • What is in the arr array ? Commented Feb 19, 2022 at 14:36
  • @rupam for example 10 elements in an array. Commented Feb 19, 2022 at 22:12

2 Answers 2

1

showModalDialog() method does not suspend the server-side script while the dialog is open.

The script should show all the elements one by one. But a newer dialog might close the older one. So, you probably only see the last one. If you want to show all the elements in one dialog, use JSON.stringify():

SpreadsheetApp.getUi().showModalDialog(
  HtmlService.createHtmlOutput(
    JSON.stringify(arr,null,2)
  ), 'Test'
);

Or if you want to see them one by one, use Utilities.sleep():

for (var count = 0; count < 10; count++) {
  var htmlOutput = HtmlService.createHtmlOutput(arr[count]);
  var arrayOutput = SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'Test');
  Utilities.sleep(15*1000);
}
Sign up to request clarification or add additional context in comments.

Comments

1

You can just use join method

SpreadsheetApp.getUi().showModalDialog(HtmlService.createHtmlOutput(arr.join(","),"Test")

or

SpreadsheetApp.getUi().showModalDialog(HtmlService.createHtmlOutput(JSON.stringify(arr),"Test")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.