Created
December 22, 2017 11:39
-
-
Save teckl/abd4ea327fcf6177b7827ea95caf02fd to your computer and use it in GitHub Desktop.
json-to-google-form.gs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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