'Is it possible to add formatting within Ui alert/prompt? Specifically line breaks

I want to create a list of variables with a Ui alert/prompt box. Is this possible?

I've tried searching the internet for fixes with no luck. Also tried (\n) and br, also with no luck.

function Handover(){

  var ss = SpreadsheetApp.getActiveSheet();
  var ui = SpreadsheetApp.getUi();
  var buttons = ui.ButtonSet.OK
  var LiDCO = ss.getRange("Tech Dashboard!O3:O11").getValues();
  var filter = ss.getRange("Tech Dashboard!M3:M11").getValues();
  var paedfilters = ss.getRange("Tech Dashboard!Q3:Q6").getValues();
  var nox = ss.getRange("Tech Dashboard!Q8:Q11").getValues();

  var handover = ui.alert('Please check the equipment in beds: ' 
                          + 'LiDCOs: '+ LiDCO  
                          + 'Filters: '+ filter 
                          + 'Paed Filters: '+ paedfilters 
                          + 'Nitric: '+ nox 
                          + ' and update the Dashboard.', buttons)
  }

I expected the Ui box to list the 4 variables on separate lines but the result just had one long string.



Solution 1:[1]

Showing the alert using the code below worked for me. You can insert carriage-return/line feeds using the \r\n sequence like this:

function showAlerts() {
  var ui = SpreadsheetApp.getUi();
  var buttons = ui.ButtonSet.OK
  var handover = ui.alert('Please check the equipment in beds: ' 
                          + '\r\nLiDCOs: '+ 12  
                          + '\r\nFilters: '+ 15 
                          + '\r\nPaed Filters: '+ 234
                          + '\r\nNitric: '+ 63 
                          + '\r\nand update the Dashboard.', buttons)
}

Solution 2:[2]

Try to use this which uses html to format text.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 PeterT
Solution 2 Jorge Murcia