4
votes

I'm using php to write data into google sheets. However, the trigger onEdit function on google sheets isn't firing when the data is written from the php. Here's the piece of code I used to write down the data:

$body = new Google_Service_Sheets_ValueRange(array('values' => $resultArrayGen));
$params = array('valueInputOption' => $valueInputOption);
$range = 'Main!F2:K';
$result = $service->spreadsheets_values->update($spreadsheetId, $range, $body, $params);

Is there anyway to use google services sheets api to trigger the onEdit function in google spreadsheets?

Thanks

1
No.Simple triggers only respond to user input. I think the installable onChange can do something like what want check the docs.Cooper
Another possible solution is to use one of the built in sheet triggers and run it every minute to look for changes. The way I do this is use a tracking column. I have one column that the function starts at the end of and looks back to find the last point at which data was entered. Once the code has that row number is starts iterating the new data. At the same time new new data rows are appended with a tracking marker.Jason Allshorn

1 Answers

1
votes

The onEdit trigger wont fire according to Google's documentation:

Script executions and API requests do not cause triggers to run. For example, calling Range.setValue() to edit a cell does not cause the spreadsheet's onEdit trigger to run.

You can find it here.