Skip to content

Instantly share code, notes, and snippets.

@roxberry
Created March 8, 2020 03:03
Show Gist options
  • Save roxberry/2dc14f26339c2dfc32f5713d5f6062b1 to your computer and use it in GitHub Desktop.
Save roxberry/2dc14f26339c2dfc32f5713d5f6062b1 to your computer and use it in GitHub Desktop.
function setReferees() {
Logger.log("Starting function");
var ssID = "xxxxx";
var formID = "xxxxx";
var wsData = SpreadsheetApp.openById(ssID).getSheetByName("data");
var refData = wsData.getRange(2, 1, wsData.getMaxRows() - 1).getValues();
var form = FormApp.openById(formID);
var items = form.getItems();
var refFieldId = 0;
Logger.log("Loop through items");
items.forEach(function(item) {
//Logger.log(item.getTitle() + ":" + item.getId());
if (item.getTitle() === "Referee Name")
{
refFieldId = item.getId();
}
});
Logger.log(refFieldId);
//refFieldId = 440230474;
var dropDownData = form.getItemById(refFieldId).asListItem();
var refList = [];
// convert the array ignoring empty cells
for(var i = 0; i < refData.length; i++)
if(refData[i][0] != "")
refList[i] = refData[i][0];
// populate the drop-down with the array data
dropDownData.setChoiceValues(refList);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment