title: Trying to get if statement to determine 'context' of addon app
body: <p>I'm working this Google Workspace Add-on app, I'm trying to get a function that sets the appropriate function for calling the document id depending on if it's called in the context of drive, docs, sheets, etc.</p>
  <pre class="lang-js prettyprint-override"><code>function checkContext(event){
    var itemId;
    Logger.log(event)
     if (DocumentApp.getActiveDocument().getId() != null &amp;&amp; DocumentApp.getActiveDocument().getId() != undefined)
     {
        itemId = DocumentApp.getActiveDocument().getId();
        Logger.log(itemId);
        }
    else if (e.drive.selectedItems[0].id != null &amp;&amp; e.drive.selectedItems[0].id != undefined){  
      var itemId = e.drive.selectedItems[0].id;
            Logger.log(itemId);
  
  }
    else if (SpreadsheetApp.getActive().getId() != null &amp;&amp; SpreadsheetApp.getActive().getId() != undefined){  
      var itemId = SpreadsheetApp.getActive().getId();
            Logger.log(itemId);
  
  }
    else {  
      var itemId = SlidesApp.getActivePresentation().getId();
            Logger.log(itemId);
  
  }
  </code></pre>
  <p>As you can see, I've attempted to achieve this with a nested if statement, where the <code>itemId</code> variable is set to the appropriate context depending on which getId() does NOT fail. Despite my best efforts, I always get the</p>
  <blockquote>
  <p>TypeError: Cannot read property 'getId' of null</p>
  </blockquote>
  <p>error every time the my function is triggered.</p>