I am using Google Sheets to track details about cases. After entering information on the sheet, I paste the URL to the related Doc so it is very easy to open the file from the sheet.
I want to update the description of the Doc file with information from the Sheet. When I paste the URL, I want it to pull the related column information and enter it into the Doc description.
The code is below:
function onEdit(event){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var changedCell= event.source.getActiveRange().getA1Notation();
var column = ss.getRange(changedCell).getColumn();
if(column == "19"){
var cellValue = ss.getRange(changedCell).getValue();
var id = cellValue.replace("https://drive.google.com/a/mine.net/file/d/","")
.replace("https://drive.google.com/open?id=","")
.replace("/view?usp=sharing","")
.replace("&authuser=0","");
var row = ss.getRange(changedCell).getRow();
var desc = Utilities.formatDate(ss.getRange("B"+row).getValue(),"GMT","MM/dd/yyyy")
+" "+ss.getRange("C"+row).getValue()
+" "+ss.getRange("D"+row).getValue()
+" "+ss.getRange("E"+row).getValue();
var file = DriveApp.getFileById(id);
file.setDescription(desc);
}
}
When I run this through debugger, it works perfectly (if I force the changedCell
and column
information) and I see the updated description in the related file.
However, when I try to run it from the spreadsheet, I get this error:
[14-11-23 19:40:31:061 MST] Execution failed: You do not have permission to call getFileById (line 104, file "Code") [0.006 seconds total runtime]
If I don't have permission, why will it run in debug? And, how do I grant permission? I have full access to both files.
On a related note, is there a better way to extract the id from the url?
UPDATE
Here is a screen shot of were I setup the trigger and the called function
Even after changing column to a number it still never even hits the alert.