Reputation: 15
I've developed a google spreadsheet with associated apps script, which creates files in google drive. Manifest (appsscript.json has of course been updated accordingly). When running script, created files are owned by me (obviously). I developed this script for another entity, with its own Google account. So, when work was finalized, I changed the ownership of my spreadsheet to the "final" owner, and this owner accepted the ownership. The point is that, when this user uses the spreadsheet and triggers files creation, the owner of created files is still... me. I guess there is a reason which this behaviour is obvious, but can't figure what.
So my question is 2-folded:
I can provide some extracts of script, but IMO this question is very high level so I don't know what to provide, except that I use Folder.createFile(fileName, fileContent, mimeType)
function, and that appsscript.json is like:
"oauthScopes": [
"https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/spreadsheets.readonly",
"https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/script.container.ui"
]
Many thanks for help, Emmanuel
Here is details of what I did:
Saving function code:
function saveEntityIntoGDrivePDF(entitySheet) {
const entitysBook = SpreadsheetApp.getActiveSpreadsheet();
const paramSheet = entitysBook.getSheetByName("Paramètres généraux");
const entitysStorageFolderOnGDriveId = paramSheet.getRange('B30').getValue();
const entitysStorageFolderOnGDrive = DriveApp.getFolderById(entitysStorageFolderOnGDriveId);
const authorizationToken = ScriptApp.getOAuthToken();
const exportLink = "https://docs.google.com/spreadsheets/d/"+entitysBook.getId()+"/export?format=pdf&size=a4&portrait=true&scale=4&top_margin=1.00&bottom_margin=1.00&left_margin=0.50&right_margin=0.50&gridlines=false&printnotes=false&pageorder=2&horizontal_alignment=CENTER&vertical_alignment=TOP&printtitle=false&sheetnames=false&fzr=false&fzc=false&attachment=false&r1=0&r2=40&c1=1&c2=6&gid="+entitySheet.getSheetId();
const year = entitySheet.getRange('J5').getValue();
const month = entitySheet.getRange('N6').getValue();
const entityIndex = entitySheet.getRange('J7').getValue();
const exportParams = {
method:"GET",
headers:{Authorization:"Bearer "+authorizationToken},
muteHttpExceptions:true
};
const entityOk = entitySheet.getRange('K26').getValue();
var success;
var entityPDFFileName = "";
if ( entityOk ) {
entityPDFFileName = "Entity_OK_"+year+"_"+month+"_"+entityIndex+".pdf";
}
else {
entityPDFFileName = "Entity_"+year+"_"+month+"_"+entityIndex+".pdf";
}
if ( !driveFileExists(entitysStorageFolderOnGDrive,entityPDFFileName) ) {
var entityPDFContent = UrlFetchApp.fetch(exportLink, exportParams).getBlob().setName(entityPDFFileName);
entitysStorageFolderOnGDrive.createFile(entityPDFFileName, entityPDFContent, MimeType.PDF);
success = true;
}
else {
success = false;
}
return success;
}
Upvotes: 0
Views: 99
Reputation: 50445
Installable triggers have separate ownership and is associated with a Google account. Installable triggers runs under the authority of the user, who created the trigger. It cannot be transferred.
The new user has to create a new trigger.
Upvotes: 0