title: For a given clock trigger, how can I retrieve the associated document/spreadsheet?
body: <p>I've built a Google Sheets add-on where users can add a time-based trigger on any spreadsheet they own. The trigger then later calls a function that retrieves some content from an API and adds it to the respective spreadsheet.</p>
  <p>It does that by first calling the <code>PropertiesService.getDocumentProperties()</code> function and retrieving some information regarding what content to add to that spreadsheet. This information was initially set when the trigger was created. It thus seems that time-based triggers always know to retrieve the properties associated with the document they were created in, without needing to specify the document ID explicitly (the <code>getDocumentProperties()</code> doesn't even support a parameter anyway).</p>
  <p>What I have trouble with is, given a list of triggers, such as looping from <code>getProjectTriggers()</code>, how can I tell which spreadsheet each trigger has been associated with / created from?</p>
  <p>PS: I've tried <code>getTriggerSourceId()</code>, but for clock triggers this always returns <code>null</code> (which is odd, since this would be the perfect function to retrieve that information).</p>
  <p><strong>EDIT: Here's a sample of code:</strong></p>
  <pre class="lang-js prettyprint-override"><code>    function setTrigger(form) {
  
      // Use the current document properties to store what kind of data should the trigger fetch
      const props = PropertiesService.getDocumentProperties();
  
      // Set Properties
      const currentSpreadsheetId = SpreadsheetApp.getActiveSpreadsheet().getId();
      props.setProperty('backupSpreadsheet', currentSpreadsheetId);
      props.setProperty('triggerValue1', form.t1);
      props.setProperty('triggerValue2', form.t2);
      props.setProperty('triggerValue3', form.t3);
  
      // Create Clock Trigger to run every day.
      const triggerId = ScriptApp.newTrigger('getData')
          .timeBased()
          .atHour(8)
          .everyDays(1)
          .create()
          .getUniqueId();
  }
  
    function getData() {
  
      // Get the document properties where the trigger was created
      const props = PropertiesService.getDocumentProperties();
  
      // Set up object to store backup info for data retrieval
      const data = {};
  
      // Get spreadsheet id and trigger config from properties
      data.spreadsheet = props.getProperty('backupSpreadsheet');
      data.t1 = props.getProperty('triggerValue1');
      data.t2 = props.getProperty('triggerValue2');
      data.t3 = props.getProperty('triggerValue3');
  
      // Open the spreadsheet and write the data to it
      const ss = SpreadsheetApp.openById(data.spreadsheet);
      writeDataToSpreadsheet(ss, data);
  
    }
  </code></pre>
  <p>The user can use the add-on UI (sidebar feature) to enable such a trigger using an HTML form on any spreadsheet they choose. The form data gets passed to the active spreadsheet's document properties, so that the trigger will be able to fetch any configuration data necessary in order to run (the <code>PropertiesService.getDocumentProperties()</code> function always returns the properties for the document where the trigger was initially created, so it's definitely the case that the trigger is associated with that spreadsheet). The user can thus have multiple clock triggers, with the limitation of one per spreadsheet.</p>