Hi I'm using script1 to save a pdf of my sheet to a folder with the year and month what I'm trying to do is get my script1 to call on script2 to return the value of FID (FolderID) from script2 to the script1 so the file can be created in the folder matching the year and month from the date it's being created. here's my script1 and script2 I'm not sure how to send the FID value from script2 to script1. Thanks
function script1() {
var source = SpreadsheetApp.getActiveSpreadsheet();
var ticketnum = source.getSheetByName("Ticket").getRange('J1').getValue();
var spreadsheet = spreadsheetId ? SpreadsheetApp.openById(spreadsheetId) : SpreadsheetApp.getActiveSpreadsheet();
var spreadsheetId = SpreadsheetApp.getActiveSpreadsheet().getId();
var folderID = I NEED THIS VAR TO BE THE RETURN VALUE FROM SCRIPT2 FID
var folder = DriveApp.getFolderById(folderID);
var token = ScriptApp.getOAuthToken();
var ssID = spreadsheetId;
var url = "https://docs.google.com/spreadsheets/d/" ssID "/export"
"?format=pdf&"
'&portrait=true' //orientation, false for landscape
'&scale=4'
'&top_margin=0.25' //All four margins must be set!
'&bottom_margin=0.25' //All four margins must be set!
'&left_margin=0.05' //All four margins must be set!
'&right_margin=0.05' //All four margins must be set!
'&horizontal_alignment=CENTER' //LEFT/CENTER/RIGHT
'&gid=504778977';
var response = UrlFetchApp.fetch(url, {headers: {'Authorization': 'Bearer ' token}});
var pdf = response.getBlob().setName(ticketnum '.PDF');
folder.createFile(pdf)
}
function script2() {
var formattedDate = Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd");
var folderYearDate = Utilities.formatDate(new Date(), "GMT", "yyyy");
var folderMonthDate = Utilities.formatDate(new Date(), "GMT", "MMMM");
var parent = DriveApp.getFolderByIdAndResourceKey('0B1XvUmuAadtaVmxweF95cWl4Rkk','resourcekey=0-oKRO1w6SHP1YHfuO0JxMjA').getFoldersByName("Mountain Metis")
var yearExist = parent.next();
var yearFolders = yearExist.getFoldersByName(folderYearDate);
if(yearFolders.hasNext()){
var yearFolder = yearFolders.next()
Logger.log('Yes, There is a year folder.')
//return;
} else {
var yearFolder = yearExist.createFolder(folderYearDate)
Logger.log('There was no year folder. But created')
//return;
}
var monthFolders = yearFolder.getFoldersByName(folderMonthDate);
if(monthFolders.hasNext()){
var monthFolder = monthFolders.next()
Logger.log('Yes, There is a month folder.')
} else {
var monthFolder = yearFolder.createFolder(folderMonthDate);
Logger.log('There was no month folder. But created')
}
var FID = monthFolder.getId()
Logger.log(FID)
return(FID)
}
CodePudding user response:
Replace
var folderID = I NEED THIS VAR TO BE THE RETURN VALUE FROM SCRIPT2 FID
by
var folderID = script2();