Need to execute apps script from google sheet in App inventor

Hi everyone!
I'm developing an app that saves and store data into a google sheet. I used apps scripts to retrieve, save and download the sheet as pdf. I connected the functions of apps script to App inventor, retrieve and save data functions works fine, but when I want to execute the function (getpdf) in app inventor it doesn't work, I don't know what I'm doing wrong. I'm not expert in apps script I just copied and modify some codes that I found in web.

The script code and blocks are attached.

Thanks for the help!

AppInventor_getPDF

Is your spreadsheet "private" or "anyone with the link can view/edit" ?

Hi, my spreadsheet is anyone with the link can edit. The script is deploy as web app (anyone, even anonymous). The script works fine when I excecute form the script editor in google sheet. When I put the link on the browser like this --> https://script.google.com/macros/s/XXXXXX/exec?/id=XXXXX&sh=Factura&func=getpdf
the page shows an error: “The script completed but did not return anything

The reason I ask is that if "anyone with the link" you can build your pdf download url in the app within a web component, and save the file to the device. This may not be what you want because after creating the pdf you then save it to google drive ?

There are a couple of issues with your script that could be affecting the success of the web app. I will need to run a test on a script and sheet of my own.

As far as you know, is the pdf not being created at all?

Thanks TIMAI2. Yeah, I want to save the pdf in Google Drive, not in the device. By the other hand, when I run the blocks in app inventor, the pdf is not created, but when I run from scipt editor it works fine, it saves the pdf in GDrive.

Ah, this is because getPDF() is only a function and won't work as it is in a web app. Web apps must have a doGet() or doPost() function in order to work and must also return something, e.g. text/message.

It is not too difficult to convert what you have:
In your script...
Change function getpdf() to function doGet()
Before the closing curly brace } at the end of the script add a return, to start with something like:
return ContentService.createTextOutput('PDF Created');
Save the script and re-publish to a new version.

In your app:

You only need to send the script url because everything is hard coded into the script.
In when Web4.GotText set responseContent to a Label so you can see what the script is returning. If you get PDF created then it is job done.

You may want to read:
HOWTO: Create a Google Apps Script Web App bound to a Spreadsheet

Let us know how you get on, or ask more if still not working...

[Edit] Stackoverflow topic on this here: https://stackoverflow.com/a/57334854/2030549

2 Likes

Thanks @TIMAI2! Now I understand. I'll try what you are recommending, and I let you know if It works.

Thanks @TIMAI2 your solution works fine!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.