Reputation: 170
I'm trying to build a basic url fetch script in Google Apps Script, but I'm having a problem with the DocumentApp.getUi() function. (note: I know this seems like a duplicate of How do i use DocumentApp.getui() on a new doc, but the answer provided didn't actually answer the question, and it's from 2013)
function myFunction() {
var doc = DocumentApp.create('new_doc'); //create doc
doc.ui = DocumentApp.getUi(); // error: 'Cannot call DocumentApp.getUi() from this context.'
var vurl = ui.prompt('url');
var furl = fetch(vurl);
doc.getBody().appendParagraph(furl)
}
I know that I can't call it this way, as the other answer explained, but is there a workaround or alternate method I can use? I'm the only person that will be using this.
Upvotes: 0
Views: 803
Reputation: 38254
Considering that you are the only one that will be using this, forget about DocumentApp.getUi()
and add the URL directly as a literal.
Assuming that fetch
is function defined somewhere else in your project, then
function myFunction() {
var doc = DocumentApp.create('new_doc'); //create doc
var furl = fetch(/** replace this with your URL */);
doc.getBody().appendParagraph(furl)
}
Upvotes: 1