Can't get Hello world example to work as a web-app - google-apps-script

I am a total newbie to google-apps-script, but I can't believe the problem I'm having. I can't even get the Hello World! example to work as a web-app.
I have copied and pasted code from google's documentation website, and I still can't get it to work. (I tried more complicated stuff first, but then I started trying simpler and simpler code until I bottomed out with the below problem.)
When I publish the following code as a web-app:
function doGet() {
return ContentService.createTextOutput('Hello, world!');
}
Instead of seeing "Hello, world!" in the browser, I get the following error message:
The script completed but did not return anything.
I'm really at a loss here. I don't know how to try anything simpler, and again, the code snippet above was copied and pasted directly from the Content Service documentation page (https://developers.google.com/apps-script/reference/content/).
Any help with this problem is greatly appreciated.
Thanks in advance.

Thanks for the response Alan.
I created a new project and pasted the Hello world code into it, and it worked. I'll just work from this new project going forward.
...
Now that I have a few more minutes of experience, I think my problem was with version control. I thought that when I made a change in my code and updated the current version, then the current version published as a web app would reflect this change in my code. However, it seems that you have to create a new version of your code in order for your newly-published web-app to reflect the most recent changes in your code. My problem was that I was not creating new versions as I changed my code, so I kept accessing the old code which was always the same as when that version was first created.
(Using the Test web app for your latest code link (located in the Deploy as web app dialog which is accessed from the Publish menu) did reflect my most recent changes, but this was not adequate for my testing purposes since I was sending arguments to my web app url. (The latest code link only calls your web app with a read-only version of your web app url that has no arguments appended to it.) In order to properly test the web app with all arguments appended to the url, I needed to re-publish the new code under a different version number in order for those changes to be reflected in the web app that was published. Only then I could access this url that pointed to my latest code with all of my arguments appended.)
Again, just hitting the Update button in the Deploy as Web App dialog without specifying a new version does not actually update the current version with your new code. In order for your latest/newest code to be deployed you have to create a new version of your code that will reflect your latest changes. In order to create a new version, you first have to choose Manage versions... from the File menu and then save a new version that reflects your most recent code changes by hitting the Save New Version button. Once you have done this, you can choose to publish this new version in the Deploy as Web App dialog. The url for your web app will then access whichever version of your code that you last deployed/published.
I know that everyone on here probably already knows this, but I thought I'd clarify what my problem was (problem understanding the work-flow of the code-publish cycle) in case any newbie in the future also runs into this problem.
<<<<<UPDATE>>>>>
See the answer from Serge below about how to use the dev version of your web app url with parameters appended to it. In many cases, this can alleviate the need to create new (exec) versions of your web app as I described above if/when you are making only incremental changes to your code.
In order to get hold of your dev url in the browser address bar so you can copy it for further use (instead of getting the script.googleusercontent.com... url that is used to temporarily serve the content/output of your web app) just call an undefined function in your web app code. Then use the Test web app for your latest code link to call the dev version of your web app. This will cause an error page to be returned, and your dev url will then be available for copying in the browser address bar.

Following these steps I was able to get the Hello World Script to run:
Go to script.google.com
Paste your above code into the script area.
Save as Hello World.
Publish as version 1.0.
Go to the url it generates and "Hello, world!" is now displayed.
You can now also test the web app with the latest code when publishing.

Your statement that the .dev url is not able to support parameters is not exactly true (The latest code link only calls your web app with a read-only version of your web app url that has no arguments appended to it). Actually it does just like the exec one but you can only call this url directly from the browser (and not from another app) because only you can access the app using this special url.
demo code :
function doGet(e) {
var valToReturn = ContentService.createTextOutput('the parameter was '+e.parameter.val).setMimeType(ContentService.MimeType.TEXT);
return valToReturn;
}
The test .dev url with parameters goes like this :
https://script.google.com/macros/s/AKfycb___vWxs/dev?val='test'
and the return you get in your Browser is :

Related

HTML Service: Communicate with Server Functions, cant call

I follow the instruction here but it not work for me.
https://developers.google.com/apps-script/guides/html/communication
in Script Editor I was crate 2 file Code.gs and Index.html same as above link said. then I publish as web app. go to web app url and it show "hello world" -> it work for the Index.html but when back to Script Editor and chose View->log nothing here. Just "logging out" string show here. I guess that mean it fail to call server-side function. I still don't know how get it work.
If you published a 'Hello World' HTML page and then subsequently changed the version, you'll need to ensure that you're using the latest version of your code: developers.google.com/apps-script/guide_versions

dartdocgen: how to view docs locally

I am having trouble using dartdocgen and dartdoc-viewer to pump my JSON files to the browser. I have had success getting all the JSON files from my application but haven't had any success actually viewing them in the browser. Based on my research, the best way to do this is hosting dartdoc-viewer on a local server as mentioned by this document:
https://www.dartlang.org/tools/dartdocgen/#deploy
However I just cannot seem to get it to work following these directions (I would like to approach it via dartium):
https://github.com/dart-lang/dartdoc-viewer/
I understand that once I am able to run pub build and compile to javascript that I dump the client/build folder into my server along with the docs folder under the URL, I am golden. That's where the issue is, how to get it from the docs folder to javascript to the browser.
I would like to be able to use dartdocgen to it's full potential so can I get some ideas?
Just run dartdocgen --serve .
see https://www.dartlang.org/tools/dartdocgen/#view-locally
Is not what you are looking for?

Filemaker Using Web Viewer to build Database Navigation Menu Using Callback URLs

I would like to use the Filemaker web viewer to build and style a database navigation menu. I have found a handful of samples and I have played with the code but the problem that I am having is that it launches in another window (Note that I also have several versions of Filemaker on my desktop and it also tries to launch the pop up in Filemaker 13 when I am building in Filemaker 12).
The goal is to call the script inside of the current database and current application so that it functions as a system navigation menu. In straight HTML in a site environment I would add target="_blank" or target="_parent" to the href but I can't seem to get the syntax right to try it in the web viewer and I'm not sure if this would be the solution. Can any angel from tech heaven assist or offer any advice? Here is the sample code that I currently have that calls a Filemaker script in a local system for a google map interface. I'll be using the script differently but the structure will be the same.
"data:text/html," &"
<html>
<body>
<a href='"&"FMP://" &
Case(
IsEmpty(Get(HostIPAddress)); Get(SystemIPAddress);
not IsEmpty(Get(HostIPAddress)); Get(HostIPAddress);
)
&"/"& Get ( FileName )& "?script=Open-Detail-Map&param=" & Data::ID_Data&"'>View Map
Detail</a>
</body>
</html>"
This works for me, and it opens it in the same window. I'd recommend using FileMaker 13 for development, or uninstalling it. It launches in 13 because the URL protocol handler (FMP) is the same for both versions, so your OS uses the newest version of FileMaker to handle the URL call.
Note that triggering scripts using a URL will not work in standalone files in FileMaker Pro, only hosted files or FileMaker Go.
It is possible to call the script from another file directly in FileMaker, rather than trying to do it from a webviewer. Can you clarify why you're trying to create your navigation menu in a webviewer?
If a webviewer is not compulsory, I would recommend:
creating an External Data Source that points at the other file
Adding FileMaker buttons for your navigation
Right-click on the button you want to trigger the script, and choose "Button Setup", then choose "Perform a Script" and specify the script you want to run from the other file.
Honestly, this makes no real sense to do. I get what you are trying and it seems interesting, but build your navigation in FileMaker and display your banner ads in a web viewer. The other option, which is always available, is to just build out the solution as a PHP site using the FMP PHP API.
I realize that this is an answer for a rather old question, but I think it warrants pointing out what the solution here is...at least in modern versions of FileMaker. I don't recall exactly when this was fixed...13.05 or .06? It was present in earlier versions but wouldn't work for locally opened files, only hosted files; now it works in both.
You need to use the 'currently open file' reference in the FMP URL: "$". So your URL string should look like this:
"fmp://$/fileName?script=AScriptName&param=..."
In your code:
<a href='"&"FMP://" &
If ( IsEmpty(Get(HostIPAddress)); "$"; Get(HostIPAddress) )
&"/"& Get ( FileName )& "?script=Open-Detail-Map&param=" & Data::ID_Data&"'>View Map Detail</a>

do I need to save a new version every time I edit app script code for a UI?

following the tutorial for google app script - Building user interfaces HTMLservice section
all is well with the initial simple hello world demo - one jave script file and one HTML file.
if I edit the HTML body to,say foo bar and the use the menu item Publish - then update - the resultant web page has not changed.
if I save a new version after that minor edit and publish the new version, then sure, the new HTML is displayed.
but surely I don't have to save a new version after every edit...
are there any clues as to why "update" (without a version change) might not work - cacheing?
with many thanks
Chris
Okay so answering my own question.
The Deploy as web app dialog contains a text field with the latest URL, but a small piece of text below that says
Test web app for your latest code
latest code is a link which when pressed outputs the latest SAVE.
The URL in the text field is the latest VERSION.
Perhaps this could be part of the deploying tutorial at
https://developers.google.com/apps-script/execution_web_apps
Problem solved!

How to configure Netbeans code entry point when you use mod-rewriting

I am developing a website in PHP and I am using mod-rewrite rules. I want to use the Netbeans Run Configuration (under project properties) to set code entry points that looks like http://project/news or http://project/user/12
It seems Netbeans have a problem with this and needs an entry point to a physical file like http://project/user.php?id=12
Has anyone found a good way to work around this?
I see your question is a bit old, but since it has no answer, I will give you one.
What I did to solve the problem, was to give netbeans what it wants in terms of a valid physical file, but provide my controller (index.php in this case) with the 'data' to act correctly. I pass this data using a query parameter. Using your example of project being the web site domain and user/12 as the URL, use the following in the NetBeans Run Configuration and arguments boxes. netbeans does not need the ? as it inserts that automatically, see the complete url below the input boxes
Project URL: http://project
Index File: index.php *(put your controller name here)*
Arguments: url=user/12
http://project/index.php?url=user/12
Then in your controller (index.php in this example), test for the url query param and if it exists parse it instead of the actual Server Request, as you would do normally.
I also do not want the above URL to be publically accessible. So, by using an IS_DEVELOPER define, which is true only for configured developer IP addresses, I can control who has access that special url.
If you are trying to debug specific pages, alternatively, you can set the NetBeans run configuration to:
http://project/
and debug your project, but you must run through your home page once and since the debugger is now active, just navigate to http://project/user/12 in your browser and NetBeans will debug at that entry point. I found passing through my home page every time a pain, so I use the technique above.
Hopefully that provides enough insight to work with your project. It has worked good for me and if you need more detail, just ask.
EDIT: Also, one can make the Run Configuration Project URL the complete url http://project/user/12 and leave the Index File and Arguments blank and that works too without any special code in controller. (tested in NetBeans 7.1). I think I will start using this method.