グーグルフォームとkintoneの連携について
ゲストスペースに入っていないアプリには、連携できるのですが、
ゲストスペースに入っているアプリに反映させるには、どのように変更したらよろしいでしょうか。
実行したコードをコピー&ペーストしましょう
const getFormResponse = (e) => {
'use strict';
const itemResponses = e.response.getItemResponses();// アンケートの回答を取得
let records = '[';
records += Utilities.formatString('{"Email": { "value": "%s" }', e.response.getRespondentEmail());// 回答者のEmailアドレスの取得
for (let i = 0; i < itemResponses.length; i++) {
const itemResponse = itemResponses[i];
switch (itemResponse.getItem().getTitle()) {
case 'アポイント取得日':
records += Utilities.formatString(',"apo" : { "value": "%s" }',
itemResponse.getResponse());// 質問に対する回答を取得
break;
case '会社名':
records += Utilities.formatString(',"Company_Name" : { "value": "%s" }',
itemResponse.getResponse());// 質問に対する回答を取得
break;
case '住所':
records += Utilities.formatString(',"address" : { "value": "%s" }',
itemResponse.getResponse());// 質問に対する回答を取得
break;
case '業種':
records += Utilities.formatString(',"Industry" : { "value": "%s" }',
itemResponse.getResponse());// 質問に対する回答を取得
break;
case '担当者名':
records += Utilities.formatString(',"Person_name" : { "value": "%s" }',
itemResponse.getResponse());// 質問に対する回答を取得
break;
case '部署名':
records += Utilities.formatString(',"Department" : { "value": "%s" }',
itemResponse.getResponse());// 質問に対する回答を取得
break;
case '役職':
records += Utilities.formatString(',"post" : { "value": "%s" }',
itemResponse.getResponse());// 質問に対する回答を取得
break;
case '従業員数':
records += Utilities.formatString(',"number_of_employees" : { "value": "%s" }',
itemResponse.getResponse());// 質問に対する回答を取得
break;
case '電話番号':
records += Utilities.formatString(',"telephone_number" : { "value": "%s" }',
itemResponse.getResponse());// 質問に対する回答を取得
break;
case 'メールアドレス':
records += Utilities.formatString(',"Email" : { "value": "%s" }',
itemResponse.getResponse());// 質問に対する回答を取得
break;
case 'ホームページURL':
records += Utilities.formatString(',"HPURL" : { "value": "%s" }',
itemResponse.getResponse());// 質問に対する回答を取得
break;
case '商談予定日':
records += Utilities.formatString(',"meeting_day" : { "value": "%s" }',
itemResponse.getResponse());// 質問に対する回答を取得
break;
case '商談予定時間':
records += Utilities.formatString(',"meeting_time" : { "value": "%s" }',
itemResponse.getResponse());// 質問に対する回答を取得
break;
case '代理店名':
records += Utilities.formatString(',"Agency_name" : { "value": "%s" }',
itemResponse.getResponse());// 質問に対する回答を取得
break;
}
}
records += '}]';
Logger.log('Response JSON is "%s"', records);
return records;
}
const sendToKintone = (e) => {
'use strict';
Logger.log('Form submitted');
const subdomain = '〇〇';// サブドメイン名
const apps = {
YOUR_APPLICATION1: {appid:〇〇', name:'〇〇'', token:'〇〇''}
};
const manager = new KintoneManager.KintoneManager(subdomain, apps);// ライブラリーの初期化
let str = getFormResponse(e);
str = str.replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/\t/g, '\\t');
const records = JSON.parse(str);// JSON形式に変換
const response = manager.create('YOUR_APPLICATION1', records);// kintone レコードの生成
// ステータスコード
// 成功すれば200になる
const code = response.getResponseCode();
Logger.log('Response code is "%s"', code);
}