1
votes

I'm creating a spellchecker using the Google Docs API in an Apps Script (just a script that extends the functionality of a Google Doc), and I wan't to make this service available to users whom download it as a Web App. Problem is that when I've made my (Container-bound) script in the script editor, it is only available in the Google Document through which I created it - that is, if i open a new document, I cannot use the script.

If I "Deploy as Web App", make it available to everyone and paste the given URL, I get an error message saying that the script needs a function called doGet(), which is not in my script.

How do I go about to publish my script as a regular web app?

2

2 Answers

2
votes

I would proceed by creating two scripts: the core functionality would be deployed as a Web App and a simple container-bound script would offer an interface to call the Web App.

Since the Web App is not bound to a document you may want to follow this scheme:

function doGet(e){
    if(e.parameter.docId){
        doStuff(DocumentApp.openById(e.parameter.docId));
    }
}

Now when you deploy the app you will get a link that gives you access to the functionality.

From the container-bound script you can add some UI (e.g. an Anchor element in a side-panel) that links to the web app with the appropriate parameters

ScriptApp.getService().getUrl() + "?docId=" + DocumentApp.getActiveDocument().getId()

or use UrlFetchApp to get the results and display them in the UI.

Unfortunately this is not the same as adding the functionality across all your documents automatically, but rather a way to install only a relatively lightweight hook in each document where you want to add the functionality, instead of the full script. I am not aware of any method that can achieve that. Note that when you make a copy of a document, the copy will contain all its scripts so you can create a template for documents that need the additional functionality. This can get ackward though if you wish to mix and match multiple scripts.

The advantage of my method is that if you modify the core functionality, the change is immediately available to all your documents making use of it, with no need to update their scripts. On the other hand if the container-script needs to interact heavily with the UI it may get complicate and reduce the usefulness of separating it in two scripts.

0
votes

The answer is in your question : the main function of your script (the one that builds the UI) must be called doGet() (this is the conventional entry point of any GAS webapp, the function that you implicitly call when opening the webapp url)... but I'm afraid this will not solve your problem...

Even if I don't know what is in your script and how you wrote it I guess that it refers to the doc in which you bound it as the "active document" and that will probably be the most important issue since a webapp has no document attached to it.

Beside that, how would a spell checker work as a standalone app ? could you explain more clearly what you want to do ?