function createChannelFolder() { // identify the sheet where the data residesvar ss = SpreadsheetApp.getActive();var names = ss.getSheetByName("Completed Certifications"); //identify the cell that will be used to name the folder var ChannelName = names.getRange(names.getLastRow(), 2).getValue(); //identify the parent folder the new folder will be invar parentFolder=DriveApp.getFolderById("18jbqtJ57IWcjfrwA7K3U9lFbIJrFlwhc"); //create the new foldervar newFolder=parentFolder.createFolder(ChannelName); }
function autoFillGoogleDocFromForm(e) { //e.values is an array of form values var Timestamp = e.values[0]; var Channel = e.values[1]; var Name = e.values[2]; var Email = e.values[3]; var Title = e.values[4]; var Address = e.values[5]; var Country = e.values[6]; var Phone = e.values[7]; var Website = e.values[8]; var CountriesActive = e.values[9];; //file is the template file, and you get it by ID var file = DriveApp.getFileById('14_YgeroYctwWhWq-P7k0ayBR-PcOfQjMs2yHdkgREgs'); //We can make a copy of the template, name it, and optionally tell it what folder to live in //file.makeCopy will return a Google Drive file object var folder = DriveApp.getFolderById('18jbqtJ57IWcjfrwA7K3U9lFbIJrFlwhc') var copy = file.makeCopy(Channel + ',' + Country, folder); //Once we've got the new file created, we need to open it as a document by using its ID var doc = DocumentApp.openById(copy.getId()); //Since everything we need to change is in the body, we need to get that var body = doc.getBody(); //Then we call all of our replaceText methods body.replaceText('{{Timestamp}}', Timestamp); body.replaceText('{{Channel}}', Channel); body.replaceText('{{Name}}', Name); body.replaceText('{{Email}}', Email); body.replaceText('{{Title}}', Title); body.replaceText('{{Address}}', Address); body.replaceText('{{Country}}', Country); body.replaceText('{{Phone}}', Phone); body.replaceText('{{Website}}', Website); body.replaceText('{{CountriesActive}}', CountriesActive); //Lastly we save and close the document to persist our changes doc.saveAndClose(); }
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/cd090524-7399-4c96-9c72-4014d4ec5a21o%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/5885cd37-9a72-4b6b-bf7c-b3ed4beed198n%40googlegroups.com.
Manged to get the solution to create a new document in a new folder.
Still haven't worked out how a second empty folder being created can be avoided but the two scripts I have working are as below;
CreateChannelFolder():
function createChannelFolder() {
var ss = SpreadsheetApp.getActive();
var names = ss.getSheetByName("SHEETNAME");
var ChannelName = names.getRange(names.getLastRow(), 2).getValue();
var parentFolder=DriveApp.getFolderById("FOLDERID");
return parentFolder.createFolder(ChannelName);
}
AutoFillGoogleDocFromForm(e):'
function autoFillGoogleDocFromForm(e) {
//e.values is an array of form values
var Timestamp = e.values[0];
var Channel = e.values[1];
var Name = e.values[2];;
var file = DriveApp.getFileById('FILEID');
var folder = createChannelFolder();
var copy = file.makeCopy(Channel + ',' + Name, folder);
var newId = copy.getId();
var doc = DocumentApp.openById(newId);
var body = doc.getBody();
body.replaceText('{{Timestamp}}', Timestamp);
body.replaceText('{{Channel}}', Channel);
body.replaceText('{{Name}}', Name);
doc.saveAndClose();
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/8981e62c-844c-4de0-8d01-60382a23d551n%40googlegroups.com.