0

I need two separate forms to be accessible from the menu of my Spreadsheet. After some troubles I found this great answer from Mogsdad: Single Google Form for multiple Sheets

I used his code for embedding the form into the uiapp using the htmlservice. So my code looks exactly like his:

function launchTecForm() {
  var TecformID = '1_some_form_ID';
  var Tecform = FormApp.openById(TecformID);
  var TecformUrl = Tecform.getPublishedUrl();
  var response = UrlFetchApp.fetch(TecformUrl);
  var formHtml = response.getContentText();

  var htmlApp = HtmlService
      .createHtmlOutput(formHtml)
      .setTitle('Tec-Response')
      .setWidth(500) 
      .setHeight(450);

  SpreadsheetApp.getActiveSpreadsheet().show(htmlApp);
}

So this code worked perfectly until about 2-3 weeks ago (can't say exactly), but since then I either get the login-prompt for logging into google-apps, or I get back a server-error. The Forms are set to public, so there should not be any need to login. Finally login in doesn't work either, cause then it demands to allow cookies (which are allowed in browser settings. I guess the html-service is not capable of processing the login to the cookie.)

So how do i get the script back to work again? I didn't change anything and it is still identical to the code in the answer from Mogsdad.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • As soon as your script contains any methods that require a validated user's account, the authentication-bot will kick in, and require login. (e.g. MailApp, GmailApp, DriveApp...) I've noticed that this is true even if the code is commented out. So you may need to look at what else in the script file. ... I don't understand your comments regarding cookies, could you elaborate? – Mogsdad Aug 23 '13 at 16:19
  • So the form that should be called doesnt need any login info. It is totally public. The problem i had when it needed login, was that within the HtmlService popup-frame the login could not be acomplished. Google apps suggested that "cookies are disabled in the browser settings", wich would be needed to login. (In fact they are enabled and my idea was that tghe problem would be the HtmlService to transmit the login-input... but thats just a guess). – user2671460 Aug 28 '13 at 11:11
  • But my main problem is still unsolved: the current function does not open any form (that is public) in the HtmlService-popup. It ALLWAYS gives me a server error, wich is not further specified. I have no clue where to search for a solution. – user2671460 Aug 28 '13 at 11:13
  • If you create a new spreadsheet with the answer to the previous question, does it work for you? (It does for me.) I think that you need to look at what other functions are in your script project - authentication is based on a scan of the whole project. – Mogsdad Aug 28 '13 at 12:07
  • @Mogsdad : I can reproduce the problem on an entirely fresh spreadsheet. [link]https://docs.google.com/a/computer-bildung-berlin.de/spreadsheet/ccc?key=0Aim_vzGB7jNLdF80VnJuTXdHN0ppbk9zOGZzdTV6RUE#gid=0 I cant find any difference to your example except that i bind the function to a custom menu. Ty for ur help and time :) – user2671460 Aug 29 '13 at 16:10

1 Answers1

1

You got caught by changes in the HtmlService. As announced in May 2013, Google has been changing the defaults for the ECMA sandbox mode used by scripts.

The good news is that you just need to specify the NATIVE sandbox mode, and the form embedding will resume functioning.

  var htmlApp = HtmlService
      .createHtmlOutput(formHtml)
      .setSandboxMode(HtmlService.SandboxMode.NATIVE)
      .setTitle('Tec-problem')
      .setWidth(500) 
      .setHeight(450);
Mogsdad
  • 44,709
  • 21
  • 151
  • 275
  • 1
    Thanx again and a lot! U made my day... now it works again, at least for the test-spreadsheet. I think i will get it to work again in the complex workflow i need it in. But now i am a good step further. I guess i have to seperate the parts of the scripts wich use authentication from the htmlservice parts now. I'll see... if i dont get it i will be back :) Ty and have a good day! – user2671460 Aug 29 '13 at 16:52