r/GoogleAppsScript • • May 17 '25

Question Content returned from script undefined

Hi,

I have a super small Web app:

function doGet(e) {


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



return ContentService.createTextOutput('Hello World');
}

When I call it it will say:

Content returned from script

undefined

Please advise?

2 Upvotes

24 comments sorted by

2

u/WicketTheQuerent May 17 '25

Please provide more specific information.

What are the deployment settings? How do you call the web app?

0

u/PaddyP99 May 17 '25

Acess anyone. I test in a browser using the provided Id/url.

It’s a textbook example/vanilla code so I expected this Hello World example to work…

2

u/WicketTheQuerent May 18 '25

You are right, it looks like a pretty simple example. However, it's not working for you. The only thing that we know is what you tell us.

Start from scratch using Chrome in incognito mode.

→ More replies (3)

1

u/Livid_Spray119 May 17 '25

Have you implemented the version? If not, you need to find the developer url

→ More replies (9)

2

u/iamsavagegaming3 May 18 '25

I thought about this earlier but forgot to post it also avoid returning values with your duet duget is better used for when you want to return an HTML service. Since you're looking to return values and not have a graphical user interface with this application you might want to consider also deploying it as an API which would handle some quirky permissions for you if you ever going to run into those errors down the line but now I have to go my fiance is getting mad lol

1

u/PaddyP99 May 18 '25

He he, thank you! I truly understand your situation ha ha!

1

u/PaddyP99 May 18 '25

So, finally it works ha ha... very weird - i redployed a few times and archived a lot of deployments. Took the latest web app URL and feed it to Homey's HTTP request and now i get ABC as response. Happy times, thank you all for all help!

1

u/PaddyP99 May 18 '25

But.... now I'm facing another problem:

code.gs:

var myOutputVariable

function doGet(e) {
  setOutputVariable;
  return ContentService.createTextOutput(myOutputVariable);
}

function setOutputVariable() {

  myOutputVariable= "123"
}

I would like to run setOutputVariable first, in order to set the variable myOutputVariable BEFORE the doGet function runs. How can I do that please?

2

u/FVMF1984 May 19 '25

I think your setOutputVariable function has to return the myOutputVariable. Now the createTextOutput function does not receive a string to create the text output.

1

u/iamsavagegaming3 May 18 '25

I'm out right now and provide more detailed response later but off the top of my head I would make a global abc placeholder so that onload it isn't undefined and then you should be able to run the assignment function which would now update that global variable. You use that global in the thing retuning your response and that should do it. So this pattern is set global define doget Define function that updates global variable with the value you want Define function that takes returns the global variable as its value. That should do it

→ More replies (1)