I have an onEdit function in a spreadsheet that I need to copy over to another spreadsheet where the other spreadsheet is an identical copy, with the same sheet name. It was working perfectly the last time i checked but that was a couple of days ago and it now has just stopped.
The Code:
function onEdit(e){
// Logger.log("working so far 1");
// mainfile();
Logger.log("working so far 4");
// var ss=SpreadsheetApp.openById(mainssid);
var ss=SpreadsheetApp.openById("Sheet ID");
var sh=ss.getSheetByName(e.range.getSheet().getName());
var rg=sh.getRange(e.range.rowStart,e.range.columnStart);
rg.setValue(e.value);
}
function mainfile(){
Logger.log("working so far 2");
var SSID = SpreadsheetApp.getActiveSpreadsheet().getId();
var folder = DriveApp.getFileById(SSID).getParents().next().getName();
var files = DriveApp.getFoldersByName(folder).next().getFiles();
var array = [];
while (files.hasNext()) {
var file = files.next();
array.unshift(file.getName());
}
array.sort();
var mainss = array[0];
var mainssid = DriveApp.getFilesByName(mainss).next().getId();
Logger.log(mainssid);
Logger.log("working so far 3");
}
What I would the mainfile function just gets me the id of a specific file and the commented out sections were just where I was trying to implement that into the onEdit function. So the expected result is for me to make an edit on one spreadsheet and for the same change to happen on the other spreadsheet, and the log would say Woriking so far for numbers 2,3,4 but nothing appears.
When I run the mainfile function it works perfectly. I am also aware that this might be a repost of here but seen as they didn't actually get an answer and it just fixed itself I thougt it might not qualify.
It isn't a replica of the other post because I'm not trying to send an email. I have looked at the simple triggers guide and I can't figure out what is wrong with this code as it doesnt ask for permission to run the function normally so i don't think I need autharisation to run it, I know that it can modify other files because it used to work and I have had it work today, it doesnt run for longer than 30 seconds and I haven't exceeded the quota. none of the others seem to apply. Please can you explain to me what I'm doing wrong because I don't understand.
I've also replaced the sheet ID with sheet ID. all credits for onEdit() code go t Cooper.
Thanks in advance, sorry for the rant.
onEdit
). You can view all the issues with your function execution by checking your Stackdriver Logs – tehhowch