Given this URL:
https://script.google.com/macros/s/MacroName/dev?theArg="69.28.15.332"
The important part is on the end:
?theArg="69.28.15.332"
I'm trying to pass information to an Apps Script in the URL.
Why won't my .gs
Google Apps Script function get the value of the string at the end of the URL? This is the doGet(e)
function.
function doGet(e){
var passedInIP = e.parameter.theArg;
Logger.log(passedInIP);
if (passedInIP === "69.28.15.332")
{
return HtmlService.createHtmlOutput("<h2>something</h2>")
}
};
I get this error msg printed in the browser:
The script completed but did not return anything
The Logger.log
does log something. It logs [Date Time EDT] "69.28.15.332"
and the value is exactly the same in the log, as the value I'm checking for. But the equality test fails.
Requirements for web apps It contains a doGet(e) or doPost(e) function. The function returns an HTML service HtmlOutput object or a Content service TextOutput object.
Handle POST Requests with Google ScriptsThe callback function doPost is invoked when an HTTP POST request is make to your Google Script URL that is published as a web app with anonymous access. const doPost = (request) => { console. log(request); return ContentService. crateTextOutput(JSON.
Here, the event is the submission of the Google Form, the effect is the function call ( onFormSubmit ). After creating the function, your script editor should look like this. Click on the stopwatch button to open the Apps Script Dashboard & create a trigger. Click on the stopwatch icon to create a trigger.
Use the Apps Script execution log To view these logs, at the top of the editor, click Execution log. When you run a function or use the debugger, the logs stream in real time. You can use either the Logger or console logging services in the built-in execution log.
The argument is passed "as it is", you can test it using a code like below :
function doGet(e){
var passedInIP = e.parameter.theArg;
Logger.log(passedInIP);
if (passedInIP == "69.28.15.332")
{
return HtmlService.createHtmlOutput("<h2>something</h2>")
}
return HtmlService.createHtmlOutput(passedInIP)
};
This will return "69.28.15.332"
including quotes...
So you have 2 possibilities to choose from :
I would choose the first one but for no good reason ;-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With