Skip to content

Instantly share code, notes, and snippets.

@justinmoon
Created April 17, 2016 21:04
Show Gist options
  • Save justinmoon/c15e594f5e989191fc52855fc9695a3e to your computer and use it in GitHub Desktop.
Save justinmoon/c15e594f5e989191fc52855fc9695a3e to your computer and use it in GitHub Desktop.
function doGet(e) {
// All Udacity spreadsheet are accessible by agent (the student) running this script
var fileId = e.parameters.fileId;
// Get the file, make copy with same name, and grab new URL
var existingFile = DriveApp.getFileById(fileId);
var fileName = existingFile.getName();
var copiedFile = existingFile.makeCopy(fileName);
var newUrl = copiedFile.getUrl();
// Return HTML containing
// - A form that navigates user to new file's URL
// - A script which submits the form automatically
var html = "<form action='" + newUrl + "' method='get' id='link'></form>" +
"<script>document.getElementById('link').submit();</script>";
return HtmlService.createHtmlOutput(html);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment