I'd like to extend the @devonuto 's idea
The code below should return an array of Form fields with their properties including entry
function getPreFillEntriesMap_(id){
var form = FormApp.openById(id);
var items = form.getItems();
var newFormResponse = form.createResponse();
var itms = [];
for(var i = 0; i < items.length; i++){
var response = getDefaultItemResponse_(items[i]);
if(response){
newFormResponse.withItemResponse(response);
itms.push({
id: items[i].getId(),
entry: null,
titile: items[i].getTitle(),
type: "" + items[i].getType()
});
}
}
var ens = newFormResponse.toPrefilledUrl().split("&entry.").map(function(s){
return s.split("=")[0];
});
ens.shift();
return itms.map(function(r, i){
r.entry = this[i];
return r;
}, ens);
}
function getDefaultItemResponse_(item){
switch(item.getType()){
case FormApp.ItemType.TEXT:
return item.asTextItem().createResponse("1");
break;
case FormApp.ItemType.MULTIPLE_CHOICE:
return item.asMultipleChoiceItem()
.createResponse(item.asMultipleChoiceItem().getChoices()[0].getValue());
break;
default:
return undefined;
}
}
You have to extend getDefaultItemResponse_()
yourself to support more types of items.
This works fine for me
function run(){
Logger.log(JSON.stringify(
getPreFillEntriesMap_("1X9MBJDZYwrij8m_c7V4HbrT1cOyBu2OLRvDsnqS4Vdw"),
null,
" "
));
}
[18-07-07 17:22:46:288 MSK] [
{
"id": 1144844846,
"entry": "1854759972",
"titile": "Q1",
"type": "TEXT"
},
{
"id": 1458564606,
"entry": "1109661125",
"titile": "Q2",
"type": "TEXT"
},
{
"id": 216942465,
"entry": "1829112829",
"titile": "Q3",
"type": "MULTIPLE_CHOICE"
}
]
The snippet get_pre_fill_entries_map
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…