Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

\n not working in google apps script Browser.msgBox

I am trying the following to add line breaks to a message box but it is not working.

function showMsgBox(){
  var msg = 'name: \n \n \n Doc URL';
  Browser.msgBox("Selected Doc template:", msg, Browser.Buttons.OK);
}

I does not matter single or double quotes.

I also tried Browser.msgBox(msg); but it is all the same.

What am I doing wrong?

Thank you.

like image 537
Luciano Avatar asked Oct 09 '12 16:10

Luciano


People also ask

How do you insert a line break in Google script?

New-line characters ("\n") are converted to line-break characters ("\r").

How do you add a line in an app script?

\n : Apps Script inserts a new line when it encounters a " \n " in the string. The characters that follow a \n will be printed on the next line.

What is E in Google App script?

Simple triggers and installable triggers let Apps Script run a function automatically if a certain event occurs. When a trigger fires, Apps Script passes the function an event object as an argument, typically called e . The event object contains information about the context that caused the trigger to fire.


1 Answers

You need to double-escape "\n" for historical reasons

function myFunction() {
  Browser.msgBox("Hello\\nWorld")
}
like image 160
Corey G Avatar answered Nov 08 '22 18:11

Corey G