回答者の受講予定を設定
回答者の受講予定をカレンダーに設定し、受講予定ドキュメントを作成する。
sendInvites_関数
フォーム回答者が選択したすべての講義をカレンダーに設定します。
user:名前とメールアドレスを含むオブジェクト
respons:ユーザーが選択した講義データーの配列
/**
* Add the user as a guest for every session he or she selected.
* @param {object} user An object that contains the user's name and email.
* @param {Array<String[]>} response An array of data for the user's session choices.
*/
function sendInvites_(user, response) {
var id = ScriptProperties.getProperty('calId');
var cal = CalendarApp.getCalendarById(id);
for (var i = 0; i < response.length; i++) {
cal.getEventSeriesById(response[i][5]).addGuest(user.email);
}
}
getCalendarByIdメソッド:カレンダーIDからカレンダーオブジェクトを取得。getEventSeriesByIdメソッド: 指定されたIDのイベントオブジェクトを取得。
sendDoc_関数
フォーム回答者の受講日程のgoogleドキュメントを作成する。
user:名前とメールアドレスを含むオブジェクト
respons:ユーザーが選択した講義データーの配列
/**
* Create and share a personalized Google Doc that shows the user's itinerary.
* @param {object} user An object that contains the user's name and email.
* @param {Array<string[]>} response An array of data for the user's session choices.
*/
function sendDoc_(user, response) {
var doc = DocumentApp.create('Conference Itinerary for ' + user.name)
.addEditor(user.email);
var body = doc.getBody();
var table = [['Session', 'Date', 'Time', 'Location']];
for (var i = 0; i < response.length; i++) {
table.push([response[i][0], response[i][1].toLocaleDateString(),
response[i][2].toLocaleTimeString(), response[i][4]]);
}
body.insertParagraph(0, doc.getName())
.setHeading(DocumentApp.ParagraphHeading.HEADING1);
table = body.appendTable(table);
table.getRow(0).editAsText().setBold(true);
doc.saveAndClose();
// Email a link to the Doc as well as a PDF copy.
MailApp.sendEmail({
to: user.email,
subject: doc.getName(),
body: 'Thanks for registering! Here\'s your itinerary: ' + doc.getUrl(),
attachments: doc.getAs(MimeType.PDF)
});
}
DocumentAppクラスを参照。create(name):nameで指定された新しいドキュメントを作成。
addEditor:ドキュメントのエディ―タ―リストにemailを登録し編集可能にする。
getBody: アクティブなドキュメント本体を取得。
insertParagraph:ドキュメント名(段落)をドキュメントの指定場所に挿入する
setHeading:ヘッディング属を設定
appendTable:ドキュメント本体にテーブルを追加する。
TABLEクラス、Textクラスを参照。
getRow(0):0行目
editAsText:テキストオブジェクトとして取得
setBold(true):bold(太文字)に設定
Documentクラス参照
saveAndClose:ドキュメントをクローズする。
MailAppクラス参照sendEmail(recipient, subject, body, options) :
recipient :mailアドレス
subject :件名
body :メール内容
options : attachments bcc cc htmlBody inlineImages name noReply replyToが選択可能。
