In Google-Apps-Script I have created a function which returns a string containing the id of a spreadsheet file (this id will vary from user to user, as it is a new file copied from a template).
function findSheet(){
//Opens User's Google Drive and searches files for a spreadsheet called "blahblah" and returns the active spreadsheet
var files = DriveApp.getFilesByName("blahblah");
var file = files.next();
var newID = file.getId();
Logger.log(newID);
return newID;
}
The Logger.log(newID) shows the id name of the file in my testing. However when I try to initiate a javascript variable to that returning id string it becomes undefined.
<script>
var idname;
idname = google.script.run.findSheet();
alert(idname);
I have another google scripts app function (which is called from javascript )which uses that id string variable as a parameter in order to write user input from my html page into their google spreadsheet as part as a web app, but the id name from the javascript goes in as undefined and the function does not work.
Is there something I do not know on why the apps script string is undefined when called on by javascript?
I tried using idname.toString() to fix but it still shows as undefined when i use an alert(idname) or document.write(idname) or rewriting a paragraph
<p idname="showmeID"></p>
<script>
document.showmeID.innerHTML.idname
According to the documentation this API is asynchronous and does not return the value directly. Instead it returns the value in a callback function.