title: Receiving error when trying to getUI [Exception: Cannot call DocumentApp.getUi() from this context]
body: <p>thank you for helping</p>
  <p>I am trying to create an alert that outputs my recipients to an email that will be sent.</p>
  <p>For some reason, when I try to getUi(), I get this error</p>
  <blockquote>
  <p>&quot;Exception: Cannot call DocumentApp.getUi() from this context.&quot;</p>
  </blockquote>
  <p>Some more information:</p>
  <ul>
  <li>The script is bound to a Google Doc</li>
  <li>I have searched in the forum and haven't found an answer to this question.</li>
  <li>The function will be triggered from the Doc UI (added a menu)</li>
  <li>When deleting the &quot;let ui = DocumentApp.getUi()&quot;, the function works as expected</li>
  </ul>
  <p>Here is the code:</p>
  <pre><code>function onOpen(){
    DocumentApp.getUi()
    .createMenu('Extras')
    .addItem('Send Email [Internal]', 'sendNotes')
    .addToUi();
  
  }
  
  function sendNotes() {
    let doc = DocumentApp.getActiveDocument();
    let ui = DocumentApp.getUi(); //error was raised here
    let body = doc.getBody();
    let meetingDate = body.getChild(3).getText();
    let recepients = 'or@*****.com';
    Logger.log(meetingDate);
    let file = DriveApp.getFileById(doc.getId());
    GmailApp.sendEmail(recepients , meetingDate + ' | eToro | Meeting Notes', 
    `Hey Team,  
  
  I hope you are well
    
  Here are the meeiting notes for this weeks weekly. (Also updated in Drive)
    
  Cheers,`, {
    attachments: [file.getAs(MimeType.PDF)],
    name: 'Meeting notes ' +meetingDate
    })
  
  
  
  }
  </code></pre>
  <p>Thank you very much for the help!</p>