Created
May 15, 2013 04:31
-
-
Save soundTricker/5581654 to your computer and use it in GitHub Desktop.
I/O 2013のGoogle Apps Script Update その1 Form上のGASとFormApp ref: http://qiita.com/items/42266e56c0212ce6b997
This file contains 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 createNewForm() { | |
var form = FormApp.create('フォームのタイトル'); | |
} |
This file contains 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 showDialogByHtml() { | |
var ui = FormApp.getUi(); | |
ui.showDialog(HtmlService.createHtmlOutput("<p>コンテンツ</p>").setTitle("タイトル")); | |
} | |
function showDialogByUiApp() { | |
var ui = FormApp.getUi(); | |
var uiapp = UiApp.createApplication() | |
ui.showDialog(uiapp.add(uiapp.createLabel('コンテンツ')).setTitle('タイトル')); | |
} | |
function showSidebarByHtml() { | |
var ui = FormApp.getUi(); | |
ui.showSidebar(HtmlService.createHtmlOutput("<p>コンテンツ</p>").setTitle("タイトル")); | |
} | |
function showSidebarByUiApp() { | |
var ui = FormApp.getUi(); | |
var uiapp = UiApp.createApplication() | |
ui.showSidebar(uiapp.add(uiapp.createLabel('コンテンツ')).setTitle('タイトル')); | |
} |
This file contains 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 getFormInstance() { | |
//現在表示ているまたは、トリガー時に動作しているフォームを取得 | |
var form = FormApp.getActiveForm(); | |
//URLに記載されているkeyパラメータを利用して取得 | |
var formA = FormApp.openById("url上のkeyパラメータ"); | |
//URLを利用して取得 | |
var formB = FormApp.openByUrl("URL"); | |
} |
This file contains 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 フォーム項目の追加_取得_修正_削除() { | |
var form = FormApp.getActiveForm(); | |
var textItem = form | |
.addTextItem() //フォームにテキスト形式の質問を追加 | |
.setTitle('質問のタイトル') //質問にタイトルを設定 | |
.setHelpText('質問の注意書き') //質問の注意書きを設定 | |
.setRequired(true) //質問が必須回答か否かを設定(trueで必須) | |
; | |
//フォームの項目を取得 | |
var item = form.getItems()[0]; | |
//項目をテキスト形式として扱い、タイトルを修正 | |
item.asTextItem().setTitle('タイトルを修正'); | |
//項目を削除 | |
form.deleteItem(item); | |
//form.moveItem(from, to)で場所を変更することも可能です。 | |
} |
This file contains 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
var ui = FormApp.getUi(); | |
ui.createMenu("メニューのタイトル") | |
.addItem('メニュー内の項目名', '起動するGoogle Apps Scriptのメソッド名') | |
.addToUi(); |
This file contains 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 フォームの回答周り() { | |
var form = FormApp.getActiveForm(); | |
//form.getResponses()で全ての回答(FormResponseの配列)が取得できる。 | |
//FormResponseは各項目が全て詰まった、ユーザの回答情報オブジェクト | |
//form.getResponses(new Date())などで日付を絞った回答も取得できる。 | |
var responses = form.getResponses(); | |
var response = responses[0]; | |
//各項目の回答情報を取得 | |
var itemResponses = response.getItemResponses(); | |
for(var i = 0; i < itemResponses.length; i++) { | |
var itemResponse = itemResponses[i]; | |
//getResponseで実際の回答を取得できる。 | |
Logger.log(itemResponse.getResponse()); | |
} | |
//回答者のメールアドレス(ただしFormsの機能を利用して収集している場合 多分Google Apps for Business等を利用している場合のみ可能) | |
Logger.log(response.getRespondentEmail()); | |
//回答時間 | |
Logger.log(response.getTimestamp()); | |
//編集用のURL これも許可している場合のみ? | |
Logger.log(response.getEditResponseUrl()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment