मुझे वेरिएबल के लिए अपरिभाषित प्राप्त हो रहा है: नाम कोई भी मदद क्यों नहीं है कि यह परिणाम प्रदर्शित नहीं कर रहा है। यह लॉगर में प्रदर्शित होगा लेकिन खोज के बाद index.html या वेब पक्ष पर नहीं होगा।वैरिएबल रिटर्न अपरिभाषित
कोड:
// var names =[]; //I tried using a global variable but with no luck
function SearchFiles(searchTerm) {
var searchFor = "title contains '" + searchTerm + "'";
var owneris = "and '[email protected]' in Owners";
var names = [];
var fileIds = [];
Logger.log(searchFor + " " + owneris);
var files = DriveApp.searchFiles(searchFor + " " + owneris);
while (files.hasNext()) {
var file = files.next();
var fileId = file.getId(); // To get FileId of the file
fileIds.push(fileId);
var name = file.getName();
names.push(name);
}
for (var i = 0; i < names.length; i++) {
//this is showing in the Logger
Logger.log(names[i]);
Logger.log("https://drive.google.com/uc?export=download&id=" + fileIds[i]);
}
}
function returnNames(names) {
return '<h3><b>returnNames has ran.!</b></h3> <br>' + names; // Why does this names variable return undefined???
}
function doGet(e) {
var template = HtmlService.createTemplateFromFile('Index');
return template.evaluate()
.setTitle('Search Drive')
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
function processForm(searchTerm) {
var resultToReturn;
Logger.log('processForm was called! ' + searchTerm);
resultToReturn = SearchFiles(searchTerm);
Logger.log('resultToReturn: ' + resultToReturn)
// shows as undefined in the logger
return resultToReturn;
}
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
function displayMessage() {
var searchTerm;
searchTerm = document.getElementById('idSrchTerm').value;
console.log('searchTerm: ' + searchTerm);
google.script.run.processForm(searchTerm);
google.script.run.withSuccessHandler(handleResults).returnNames();
}
function handleResults(searchTerm) {
console.log('Handle Results was called! ');
document.writeln(searchTerm);
}
</script>
</head>
<body>
<input type="text" id="idSrchTerm" name="search">
<input type="button" value="submitButton" name="submitButton" onclick="displayMessage()" />
</body>
</html>
आपको किस लाइन में त्रुटि मिल रही है? इससे इस मुद्दे को डीबग करने में मदद मिल सकती है। – Rikin
मुझे फ़ंक्शन रिटर्न नाम (नाम) लाइन पर अपरिभाषित हो रहा है- आप देख सकते हैं कि मैंने – OblongMedulla
कई मुद्दों पर टिप्पणी की है। सबसे पहले इंडेक्स कॉल में आप वापस नाम() पर कुछ भी नहीं दे रहे हैं। इस प्रकार जब फ़ंक्शन चलता है तो यह अनिर्धारित हो जाता है और शायद प्रिंट अपरिभाषित होता है। दूसरा, मुझे लगता है कि आप मानते हैं कि नाम वैश्विक रूप से उपलब्ध होंगे जो मैं इसे नहीं देखता हूं। – Rikin