google-apps-scripttriggers

How to identify whether Google Apps Script is launched as a Trigger or Manually?


How can I identify in Google Apps Script whether the script itself was triggered by some event or it was launched by someone?


Solution

  • Technically that is possible. If you are using simple triggers you must not call the function from another function. In that case you simply use your function as let's say onEdit(e) and try to check the values of e. For example check what is the value of e.source. Simple triggers will generaly have that value. Review this page to see what event handlers you can look for.

    With installable triggers it's easier. Let's say you have function1(e) which you set up a trigger for. You can now check if you have a value for e.triggerUid. You can also use that value to delete the trigger if you want!