I am struggling with how to get the ID from the google script sheet back into the HTML sheet. I am hoping to use the parentfolder ID of the activespreadsheet to be the folder that opens with the picker. The spreadsheet will only be in one folder so will have only 1 parent.
This is the code I was going to use to find the folder ID
function ThisFilePF() {
var FileID = SpreadsheetApp.getActiveSpreadsheet().getId()
var ThisFileParentFolders = DriveApp.getFileById(FileID).getParents()
return ThisFileParentFolders.next().getId()
}
I am then wanting that folder ID (pkrPF) to be used in the HTML sheet when the picker is being built.
function createPicker(token) {
if (pickerApiLoaded && token) {
google.script.run.ThisFilePF()
var PickFolder = new google.picker.DocsView().setParent(pkrPF)
.setIncludeFolders(true)
.setSelectFolderEnabled(true);
var picker = new google.picker.PickerBuilder()
.addView(PickFolder)
.setSelectableMimeTypes('application/vnd.google-apps.folder')
.enableFeature(google.picker.Feature.NAV_HIDDEN)
.hideTitleBar()
.setOAuthToken(token)
.setDeveloperKey(DEVELOPER_KEY)
.setCallback(pickerCallback)
.setOrigin(google.script.host.origin)
.setSize(DIALOG_DIMENSIONS.width - 2,
DIALOG_DIMENSIONS.height - 2)
.build();
picker.setVisible(true);
} else {
showError('Unable to load the file picker.');
}
}
I know I am making some basic mistakes here, but any pointers would be appreciated.
EDIT: Possibly getting a little closer, but still not sure how to get the variable data into the createpicker function.
I changed google.script.run.ThisFilePF() to google.script.run.withSuccessHandler(getPkrFdrView).ThisFilePF();
and added this function
function getPkrFdrView(pkrPF) {
pkrPFID = pkrPF
alert("pkrPFID = " + pkrPFID)
}
The alert popup shows the Folder ID gets pulled through. I just need to work out how that gets to the createpicker function. I have read that you should avoid using Global Variables in javascript, so this is the next hurdle.