Take the 2-minute tour ×
Web Applications Stack Exchange is a question and answer site for power users of web applications. It's 100% free, no registration required.

We are trying to link a list on a Google Spreadsheet to a drop down menu on a Google Form.

The twist is that this Google Spreadsheet list will be continuously updated and needs to automatically update the form.

I'm borrowing this code we found online:

var FORMID = "1aGrHm7x39kAJ-iJlFvp58saZHyARyB92uCbyvxGqE7M";
var LIST_DATA = [{title:"Which Document Did You Use?", sheet:"Documents"}]

function onOpen(e){
  var menuEntries = [];
  menuEntries.push({name: "Update Lists", functionName: "updateLists"});
  SpreadsheetApp.getActiveSpreadsheet().addMenu("List Updater", menuEntries)
}

function updateLists() {
  var form = FormApp.openById(1aGrHm7x39kAJ-iJlFvp58saZHyARyB92uCbyvxGqE7M);
  var items = form.getItems();
  for (var i = 0; i < items.length; i += 1){
    for (var j = 0; j < LIST_DATA.length; j+=1) {
    var item = items[i]
    if (item.getTitle() === LIST_DATA[i].title){
        updateListChoices(item.asListItem(), LIST_DATA[i].sheet);
        break;
    }
    }
  }
}

function updateListChoices(item, sheetName){
  var data = (SpreadsheetApp.getActiveSpreadsheet()
            .getSheetByName(sheetName)
            .getDataRange()
            .getValues());
  var choices = [];
  for (var i = 0; i < data.length; i+=1){
    choices.push(item.createChoice(data[i][0]));
  }
  item.setChoices(choices);
}

It worked for the creator but I'm having this error:

Missing ) after argument list. (line 11, file "Code")

Here is the spreadsheet in question: https://docs.google.com/spreadsheet/ccc?key=0AoFVL1CoqhmxdDE2UDRHbnBaNnAzUjVHLVFQcWQxSlE&usp=sharing#gid=0

share|improve this question
2  
For later questions; please include the relevant code in your question, don't just link to it. If the link goes away some day, the question will be of no use. I have edited your question to include the code. –  Vidar S. Ramdal Nov 12 '13 at 11:22
add comment

1 Answer

The line

var form = FormApp.openById(1aGrHm7x39kAJ-iJlFvp58saZHyARyB92uCbyvxGqE7M);

needs quotes around the id parameter:

var form = FormApp.openById("1aGrHm7x39kAJ-iJlFvp58saZHyARyB92uCbyvxGqE7M");

... or, use the FORMID constant you have already defined:

var form = FormApp.openById(FORMID);

Also, add a ; to terminate line 17:

var item = items[i];
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.