Skip to content

Instantly share code, notes, and snippets.

@teckl
Created December 22, 2017 11:39
Show Gist options
  • Save teckl/abd4ea327fcf6177b7827ea95caf02fd to your computer and use it in GitHub Desktop.
Save teckl/abd4ea327fcf6177b7827ea95caf02fd to your computer and use it in GitHub Desktop.
json-to-google-form.gs
function myFunction() {
var form = FormApp.getActiveForm();
var response = UrlFetchApp.fetch("https://XXXXX.example.com/google_drive_file.json");
var json=JSON.parse(response.getContentText());
Logger.log(json);
// http://www.koikikukan.com/archives/2011/04/05-025555.php
var sort_by = function(field, reverse, primer) {
reverse = (reverse) ? -1 : 1;
return function(a,b){
a = a[field];
b = b[field];
if (typeof(primer) != 'undefined') {
a = primer(a);
b = primer(b);
}
if (a<b) return reverse * -1;
if (a>b) return reverse * 1;
return 0;
}
}
// sort by createdDate
json.sort(sort_by('createdDate', false, function(a){return a.toUpperCase()}));
var item = form.addCheckboxItem();
item.setTitle('投票フォーム');
var list = [];
for (i in json) {
//Logger.log(json[i].createdDate);
var str = json[i].title + " " + json[i].ownerNames + " " + json[i].alternateLink;
Logger.log(str);
list.push(str);
}
item.setChoiceValues(list);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment