I have a Google sheet that has an onEdit triggered function that works fine if I edit the doc myself.
But when the sheet is updated via the sheet API from an external app the event does't occur. Can you help me find a method to generate this update event following a write to the sheet from an external source,
thx
Some limitations of onEdit() are described in a previous answer.
If you install that function to trigger "on change", you should catch the event. Note that the event that's delivered in this case is not as rich as an edit trigger receives. See Understanding Events.
Related
I want to run a Google App Script function every time a change is made to my Google Doc. I have found onChange and onEdit triggers which are only available for Google Spreadsheet. I am sure there must be an edit/change trigger for Google Doc as well.
Unfortunately there are no onEdit(), onChange() triggers for Google Docs.
The triggers available for Google Docs are the following:
onOpen() triggers both simple and installable;
time driven triggers;
onInstall() simple triggers.
What you can do instead is to use a time driven trigger so in this way even though the changes are not directly triggering the execution, the trigger will still run how often you want it to.
Last but not least, you can file a Feature Request on Issue Tracker where you specify the details needed.
Reference
Apps Script Trigger;
Google Issue Tracker.
my onEdit() function calling to other function when there is a change in the sheet.
if the user makes the change all works fine.
but if the change was made by google-form (the form fill some cells with the answers it gets) onEdit() does not trigger.
do I miss something?
Yes, you forgot to read the documentation for the simple triggers:
onOpen(e) runs when a user opens a spreadsheet, document, or form that he or she has permission to edit.
onEdit(e) runs when a user changes a value in a spreadsheet.
onInstall(e) runs when a user installs an add-on.
doGet(e) runs when a user visits a web app or a program sends an HTTP GET request to a web app.
doPost(e) runs when a program sends an HTTP POST request to a web app.
and installed triggers:
Even though installable triggers offer more flexibility than simple triggers, they are still subject to several restrictions:
They do not run if a file is opened in read-only (view or comment) mode.
Script executions and API requests do not cause triggers to run. For example, calling FormResponse.submit() to submit a new form response does not cause the form's submit trigger to run.
Installable triggers always run under the account of the person who created them. For example, if you create an installable open trigger, it will run when your colleague opens the document (if your colleague has edit access), but it will run as your account. This means that if you create a trigger to send an email when a document is opened, the email will always be sent from your account, not necessarily the account that opened the document. However, you could create an installable trigger for each account, which would result in one email sent from each account.
A given account cannot see triggers installed from a second account, even though the first account can still activate those triggers.
Consider what would happen if your onEdit(e) was activated by programmatic changes, such as if your onEdit function alters the spreadsheet values...
In your situation, where you want form submission to activate your on edit function, You will need to install a form submission trigger (there is no simple trigger for form submissions).
An example function to receive your form submission trigger:
function giveMeAnInstalledFormSubmitTrigger(formSubmitEventObject) {
if(!formSubmitEventObject) throw new Error("You called this from the Script Editor");
var newEventObject = /* do something with the formSubmitEventObject */;
// Call the on edit function explicitly
onEdit(newEventObject);
}
You can read more about the event objects that triggered functions receive in the Apps Script documentation: https://developers.google.com/apps-script/guides/triggers/events
onEdit() will not be triggered by another script editing a sheet or by a form submission.
You can use onFormSubmit(e) instead depending on what your function does it would be a good idea to use the e parameter of the trigger.
https://developers.google.com/apps-script/guides/triggers/events#form-submit
What i have done is that i created an extra sheet with a cell that is the same where the primarecell is(the cell that changes). Leave it for now. I open the scriptapp and write down the code(the code that should happen if the cell changes). Then i wrte down "if" and take the two value i both cells and make an trigger that goes on every minute. With that said, if The cells are the same the "if" is looping on "true". But if something change on the primary cell, it will be "false" and you use "else". Under"else" you should have what ever function you want when soemthing change in that cell. + You must have a funtion where you insert the new value form the primarycell to the "check cell" if u want this too function as loop. Otherwise the "if" code will loop "false" every minute becuse the both cells are not the same.
My english and explaining is not that good:(
I am trying to apply conditional formatting rules on a google sheet using a google apps script. I found that this could be done with the API, so I enabled it and have it all working when ran from my script ... but when I trigger the script to run from my sheet, the API batchUpdate doesn't run. I am sure I'm missing something simple ...
The code is in the Themes.gs project of this spreadsheet: https://docs.google.com/spreadsheets/d/1Fs6B-OmlqfoAoon5PcoAYbHq4CO8w0qPqfSRy_OQhe0/copy
specifically this bit doesn't seem to run when the script is triggered from the sheet itself:
Sheets.Spreadsheets.batchUpdate(JSON.stringify(functionname), SpreadsheetApp.getActiveSpreadsheet().getId())
A simple solution is Installable Triggers.
Rename your onEdit() function to something else, like whenWeEdit().
Click the link that says: No triggers set up click here to add one now.
Under Run, select whenWeEdit (or whatever you renamed your function as).
Under Events, select From spreadsheet.
Next, instead of On open, select On edit.
Click save.
Edit the sheet. Your function now seems to work for me. What about you?
I want to have a Goggle Apps Script be run when a new Calendar Event is added to a Google Calendar. How can I setup the trigger? I know what I want to script (change color for an event based on the text in the Title). I just don't see where to setup the trigger to run my script.
You can use the new Google Calendar Event Triggers. You can create the code with a script similar to the following to trigger your function:
ScriptApp
.newTrigger('findNewEvents')
.forUserCalendar(Session.getActiveUser().getEmail())
.onEventUpdated()
.create()
Then you can loop through the events in your calendar to find any events recently created and pass them to your function.
Go to https://script.google.com/home/triggers (also available in your script editor, go to Edit -> All your triggers).
Create or edit the trigger for your script.
For event source use "From calendar", put "Calendar updated" to calendar details (see the image below) and specify the calendar owner email.
This feature is not supported yet as of now. You can see that no resolution has been provided in this issue tracker. You will have to rely on your own workaround implementation or open a new feature request.
I'm having an issue with doing an HTTP Post in the onOpen event in google apps script.
What I'm trying to do is send a notification to another deployed script that someone has opened one of our spreadsheets. I'd like this functionality to persist even when someone copies the spreadsheet so that we can track where those are as well.
My problem is that if I call UrlFetchApp.fetch(url, options) from the onOpen event, I get the error - "Execution failed: You do not have permission to call fetch" however the fetch does work if I create a trigger using the ui that fires when the spreadsheet is opened. The problem with this approach is those triggers are not copied when the spreadsheet is copied.
Any suggestions for a possible solution or a simple workaround would be greatly appreciated.
Thanks,
Mark.
There are two types of triggers - simple and installable. The onOpen is a simple trigger and there are limitations on what you can do within a simple trigger and doing an UrlFetch is one of them. You can read more about simple & installable triggers at https://developers.google.com/apps-script/understanding_triggers