Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get an 'Invalid argument: url' error in the openByUrl(formURL) call?

I have a form created in a Google Apps spreadsheet and I am trying to find out some of the forms parameter data in my script.

In the following code I don't understand why I am getting an 'Invalid argument' error at the line

var myForm = FormApp.openByUrl(formURL);

even though the log shows what I think is a valid formURL string.

function myFunction() {
  var ss  = SpreadsheetApp.getActive();
  var formURL = ss.getGetFormURL();
  Logger.log('Spreadsheet\'s formURL: %s', formURL);

  var myForm = FormApp.openByUrl(formURL);  // Google script shows the ERROR here
  Logger.log('Form PublishedURL: %s', myForm.getPublishedUrl());

}
like image 736
user2419137 Avatar asked May 24 '13 22:05

user2419137


2 Answers

Try opening the form using its ID rather than the URL. You can find the ID of the form from its URL.

 var myForm = FormApp.openById(id)
like image 178
ECWyne Avatar answered Nov 07 '22 02:11

ECWyne


openById and openByUrl only works with the NEW forms service. So if form was created with old service, it won't work. See:

http://code.google.com/p/google-apps-script-issues/issues/detail?id=2866

like image 1
Norman Cousineau Avatar answered Nov 07 '22 03:11

Norman Cousineau