Reputation: 11
How can you pull information from a google spreadsheet back into a google form to update the information?
I would like to be able to have the information I have already submitted through a Google Form be pulled up again in the form to update information. I am aware that I can go and edit the spreadsheet but for my purpose it would be easier to do it through the form. I have been unable to locate a script that would allow me to do this. Does anyone have any suggestions?
Upvotes: 1
Views: 991
Reputation: 847
You are able to use FormApp in Apps Script to access the form objects for updating.
Below is an example that updates a "Choose from List" object. If you wanted to update the form after each submission, you could could call the updateList function using the container based trigger "On form submit".
function updateList(){
var form = FormApp.openById(formId);
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
// get the range of values to update in the form
var data = sheet.getRange(2,1,sheet.getLastRow(),sheet.getLastColumn()).getValues();
var listItemsToAdd = [];
for(s in data){
if(logic to define if to add to the form){
listItemsToAdd.push(data[s][0]);
}
}
// get all the list items in the form
var list = form.getItems(FormApp.ItemType.LIST);
// grab the first list item in the array of the form's list items
var item = list[0].asListItem();
// set the options to the array just created
item.setChoiceValues(listItemsToAdd);
}
Upvotes: 3