function createAndSendDocument() {
// Create a new document with the title 'Hello World'
var ui = DocumentApp.getUi();
var response1 = ui.prompt('What should be Name of your Document', ui.ButtonSet.YES_NO);
var doc = DocumentApp.create(response1.getResponseText());
var response = ui.prompt('What should be content of your Document', ui.ButtonSet.YES_NO);
// Add a paragraph to the document
var paragraph = prompt("What should be content of your Document")
doc.appendParagraph(response.getResponseText());
// Save and close the document
doc.saveAndClose();
// Get the URL of the document
var url = doc.getUrl();
// Get the email address of the user
var response2 = ui.prompt('What should be content of your Document', ui.ButtonSet.YES_NO)
var emailAddress = response2.getResponseText();
// Send the user an email with a link to the document
GmailApp.sendEmail(emailAddress,
'Hello from my first Google Apps Script!',
'Here is a link to a document created by my ' +
'first Google Apps Script: ' + url);
}
This the code I entered, and it resulted in an Error:
"Cannot call DocumentApp.getUi() from this context. (line 3, file "Code")"
What is the problem in the code?