The script has been completed but the returned value is of unsupported type

Hello everyone. I'm a beginner but very curious. I'm trying to recreate this tutorial https://www.youtube.com/watch?v=enjBJVAjPsQ&list=PLYpA2ciX_qTwA0QM4KqkzDXtGs9KCMVur&index=4

clicking a button the textbox displays a list, but it returns to me: the script has been completed but the returned value is of unsupported type.

could you help me understand why it doesn't work?

below the code I typed on App Script:

    function doGet(e) {

      return aggiorna;

    }

    function aggiorna(e)

    {

    var programma=SpreadsheetApp.getActive();

    var documento=programma.getSheetByName("Elenco");

    var testo="";

    var righe=documento.getDataRange().getValues();

    for (var riga=0;riga<righe.length;riga=riga+1)

      {

        testo=testo+righe[riga].join(",")+"\n";

      }

    return ContentService.createTextOutput(testo).setMimeType(ContentService.MimeType.TEXT);

I debugged and the testo variable correctly contains the text string.

also I read that the variable (e) of the ToGet function is undefined (is this correct?)

You didn't put an e in the script call at the top

function doGet(e) {

      return aggiorna;

change it to this, and it will work:

function doGet(e) {

      return aggiorna(e);

You could just write your google apps script like this and it will work:

function doGet() {

    var programma=SpreadsheetApp.getActive();
    var documento=programma.getSheetByName("Elenco");
    var testo="";
    var righe=documento.getDataRange().getValues();
    for (var riga=0;riga<righe.length;riga=riga+1)
      {
        testo=testo+righe[riga].join(",")+"\n";
      }
    return ContentService.createTextOutput(testo);
    }

If I enter this link https://script.google.com/macros/s/AKfycbxGax5bJoPYoFBrLoxw0Nm3j5w4cyQo3ph_Dot2S02_/dev
on the broswer it returns me the data correctly instead the MIT app continues to return me the usual message

The /dev link will not work through the AI2 app, you need to use the published link ending with /exec. If you have made changes to your google apps script, make sure you republish the script, and also check that the script url displayed is the same as the one in your AI2 app.

inserting the link / exec now the app returns me this text:

https://drive.google.com/file/d/17arV8AM2Rp3f4nMpgZOGDX3DHycEF-DK/view?usp=sharing

i still can't get google sheet data

Your spreadsheet is private. This is OK for your app because your google apps script and your spreadsheet are owned by the same account.

Have you set your script to run for Anyone (NOT anyone with a google account)?

Please show

  • your blocks
  • your script url that ends in /exec (as text, not an image)

I set my script to run for Anyone with a Google account

the screenshot is from the mobile app and shows a series of lines that I suppose are written in html.

if in the blocks I ask for the url, the app returns the address correctly. If I ask the other two he gives me the correct information. Only when I ask for the content does it give me the html information

This will not work with your app, you need to set the script to run as "Anyone"

See also:

note: this uses the legacy script editor

Deployment gives me only two choices:

  • only me
  • anyone with a google account

Scroll down a bit....

image

Believe me there is no wording: anyone

Are you using Google Workspace - inside a domain? This could be the reason you do not see "Anyone"

If this is the case, your Admin (if it is not you) will need to give you wider permissions. Alternatively, use a personal gmail account, but this may be an issue if using internal "google" data.

I use my google. I'm using the new editor, which also lacks the classic menu. Anyway I restored the previous editor and in this case I found the wording "anyone".
Finally I deleted all the lines of the doGet () function and typed only the line
return ContentService.createTextOutput ("Hello World");

But even in this way the mobile app does not return the html code

a web app requires a doGet(e) or a doPost(e) function AND a ContentService or HTMLService return in order to work. So your basic web app would, as a minimum, need to be:

function doGet() {
return ContentService.createTextOutput("Hello World");
}

I am really not sure where you problem lies, I suggest you delete the script you are working on and start again following my guide, using the legacy script editor.

I'll start from scratch by reading your guide. in the meantime I am grateful for your attention. Thank you!

First Step Solved. The problem was just getting anyone authorized.
There are two sections in the deployment definition:
1st - Run as (I entered "user accessing the web application). In the 2nd section it only showed the two options we talked about in the post above.

I changed in the 1st section with "run as me ('my email' -xxxx@gmail.com) and finally in the 2nd section" Users authorized to access "I was able to insert the words" anyone "

It works :slight_smile:

Thanks again for the assistance

thumbsup2

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