I'm using Google Forms as a tool to automate my workflow and generate documents from spreadsheet data.
To avoid typing all data twice, I'm trying to generate a form link with prefilled responses.
I can do it with this code (thanks to @Mogsdad previous response) and it works well, except when I have an optional "other" field in Checkbox and Multiple Choice optional "other" field. In this case, I'm not getting this optional value, which is just what I want, so the user won't have to retype it.
The code I'm using is this:
var ss = SpreadsheetApp.getActive();
var sheet = SpreadsheetApp.getActiveSheet();
var formUrl = ss.getFormUrl(); // Use a form attached to sheet
var form = FormApp.openByUrl(formUrl);
var items = form.getItems();
var cell_content = "Some string value in the spreadhseet";
for (var i = 0; i < items.length; i++ ) {
var id_item = items[i].getId();
var type_item = items[i].getType();
var item_of_form = form.getItemById(id_item);
if (type_item == "MULTIPLE_CHOICE"){
formItem = item_of_form.asMultipleChoiceItem();
if (formItem.hasOtherOption()){
formItem.showOtherOption(true);
}
var response = formItem.createResponse([cell_content]);
formResponse.withItemResponse(response);
}
var url = formResponse.toPrefilledUrl();
Logger.log(url);
All works fine (with Text and Paragraph responses and even with Checkbox and Multiple Choice (except with its optional value).
How can I put this optional values of checkbox and Multiple Choice in the prefilled form?