1
votes

Does anyone know if I have to have my google sheet open for the onEdit() function to work? I have a background task running that edits the sheet but my function only fires when I manually open the sheet and make an edit real time. Sheets recognizes when my edits are made (both manually and in the background) but my function won't work unless I have it open.

My function pings a url:

function onEdit() {
  UrlFetchApp.fetch("https://nosnch.in/tokenhere");
}

If sheets won't run the function when the sheet isn't opened is there any way around this?

1
Yes. You must have the sheet open for an edit to trigger it.Alan Wells
Also, you cannot send emails or fetch pages inside the onEdit trigger.Amit Agarwal

1 Answers

3
votes

onEdit is a UI triggered function.

You can have the offline background task call onEdit() directly as it concludes if it is within the same script

function backgroundTask() {
 // do stuff

 onEdit();
}

If it is in another script you'll need to call it either as a webapp or library tie-in.