# GoogleフォームからKintoneに反映されない

**URL:** <https://community.cybozu.dev/t/topic/5629>\
**Category:** kintone 開発相談\
**Created:** [2022 年 1 月 12 日午前 6:10 UTC](https://community.cybozu.dev/t/topic/5629 "2022-01-12T06:10:20Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Legacy\_Account2940](https://avatars.discourse-cdn.com/v4/letter/l/e95f7d/32.png) [@Legacy\_Account2940](https://community.cybozu.dev/u/Legacy_Account2940)\
**Post date:** [2022 年 1 月 12 日午前 6:10 UTC](https://community.cybozu.dev/t/topic/5629/1 "2022-01-12T06:10:20Z")

</div>

[https://developer.cybozu.io/hc/ja/articles/115003856483](https://community.cybozu.dev/hc/ja/articles/115003856483)

の記事を元に、見様見真似で作成したのですが、Kintoneに反映されません。

お知恵を頂けないでしょうか。

&nbsp;

～～～

```
functiongetFormResponse(e){'use strict';varitemResponses=e.response.getItemResponses();// アンケートの回答を取得varrecords='[';records+=Utilities.formatString('{"Email": { "value": "%s" }',e.response.getRespondentEmail());// 回答者のEmailアドレスの取得for(vari=0;i\<itemResponses.length;i++){varitemResponse=itemResponses[i];switch(itemResponse.getItem().getTitle()){case'お名前（フルネーム）':records+=Utilities.formatString(',"文字列\_\_1行\_\_0" : { "value": "%s" }',itemResponse.getResponse());// 質問に対する回答を取得break;case'会社名および部署名（所属）':records+=Utilities.formatString(',"文字列\_\_1行\_\_1" : { "value": "%s" }',itemResponse.getResponse());// 質問に対する回答を取得break;case'掲載（放送）予定媒体':records+=Utilities.formatString(',"文字列\_\_1行\_\_4" : { "value": "%s" }',itemResponse.getResponse());// 質問に対する回答を取得break;}}records+='}]';Logger.log('Response JSON is "%s"',records);returnrecords;}functionsendToKintone(e){'use strict';Logger.log('Form submitted');varsubdomain='{●●●●-pr}.cybozu.com';// サブドメイン名varapps={YOUR\_APPLICATION1:{appid:4,name:'kintone Meetup 参加者',token:'6p2azDdMxxWeBCS1ywfYO23Rse1qZJMNwVL13JU2'}};varmanager=newKintoneManager.KintoneManager(subdomain,apps);// ライブラリーの初期化varstr=getFormResponse(e);str=str.replace(//g,'\').replace(/\r/g,'\\r').replace(/\t/g,'\\t');varrecords=JSON.parse(str);// JSON形式に変換varresponse=manager.create('YOUR\_APPLICATION1',records);// kintone レコードの生成// ステータスコード// 成功すれば200になるvarcode=response.getResponseCode();Logger.log('Response code is "%s"',code);}

```

---

<div class="post-metadata">

**Author:** ![Legacy\_Account1384](https://avatars.discourse-cdn.com/v4/letter/l/97f17d/32.png) [@Legacy\_Account1384](https://community.cybozu.dev/u/Legacy_Account1384)\
**Post date:** [2022 年 1 月 14 日午前 4:38 UTC](https://community.cybozu.dev/t/topic/5629/2 "2022-01-14T04:38:12Z")

</div>

&nbsp;小嶋さん、こんにちは。

> Kintoneに反映されません。

何かエラーメッセージは出ていますでしょうか？  
ログを確認する方法は、次の投稿が参考になると思います。  
[https://developer.cybozu.io/hc/ja/community/posts/360060227692](https://community.cybozu.dev/hc/ja/community/posts/360060227692-Google%E3%83%95%E3%82%A9%E3%83%BC%E3%83%A0%E3%81%8B%E3%82%89kintone%E3%81%AB%E5%8F%8D%E6%98%A0%E3%81%95%E3%82%8C%E3%81%AA%E3%81%84)

---

<div class="post-metadata">

**Author:** ![Legacy\_Account2940](https://avatars.discourse-cdn.com/v4/letter/l/e95f7d/32.png) [@Legacy\_Account2940](https://community.cybozu.dev/u/Legacy_Account2940)\
**Post date:** [2022 年 1 月 19 日午前 12:20 UTC](https://community.cybozu.dev/t/topic/5629/3 "2022-01-19T00:20:03Z")

</div>

sio様

エラー  
ReferenceError: manager is not defined  
getFormResponse @ コード.gs:3

と出ました。ググっても分からず、、、よろしくお願いいたします。

---

<div class="post-metadata">

**Author:** ![Legacy\_Account1384](https://avatars.discourse-cdn.com/v4/letter/l/97f17d/32.png) [@Legacy\_Account1384](https://community.cybozu.dev/u/Legacy_Account1384)\
**Post date:** [2022 年 1 月 19 日午前 1:56 UTC](https://community.cybozu.dev/t/topic/5629/4 "2022-01-19T01:56:32Z")

</div>

小嶋 様

> ReferenceError: manager is not defined

manager が定義されていない、とのエラーになると思いますが、  
記事35行目の通り、manager は定義されていますでしょうか。

```
varmanager=newKintoneManager.KintoneManager(subdomain,apps);// ライブラリーの初期化

```

また、念のためですが、subdomainを記載する際に、サンプルコードにあった{}の記載は必要ありません。

```
var subdomain = '{●●●●-pr}.cybozu.com';// サブドメイン名

```

---

<div class="post-metadata">

**Author:** ![Legacy\_Account2940](https://avatars.discourse-cdn.com/v4/letter/l/e95f7d/32.png) [@Legacy\_Account2940](https://community.cybozu.dev/u/Legacy_Account2940)\
**Post date:** [2022 年 1 月 19 日午前 2:13 UTC](https://community.cybozu.dev/t/topic/5629/5 "2022-01-19T02:13:16Z")

</div>

function getFormResponse(e)&nbsp;

側に

Logger.log(‘response=\> “%s”’, response);

を入れてしまっていたため、function sendToKintone(e) 側（44行目）に入れました。

そうしましたところ、

TypeError: Cannot read property ‘response’ of undefined  
getFormResponse @ コード.gs:3

というエラーが表示されております。よろしくお願いします。

---

<div class="post-metadata">

**Author:** ![Legacy\_Account1384](https://avatars.discourse-cdn.com/v4/letter/l/97f17d/32.png) [@Legacy\_Account1384](https://community.cybozu.dev/u/Legacy_Account1384)\
**Post date:** [2022 年 1 月 19 日午前 2:47 UTC](https://community.cybozu.dev/t/topic/5629/6 "2022-01-19T02:47:40Z")

</div>

小嶋 様  
[こちらの投稿](https://community.cybozu.dev/hc/ja/community/posts/360060227692/comments/900000193626)の通り、記事サンプルコードの39行目の次に  
Logger.log(‘response=\> “%s”’, response); を追記すると、ログが正常に出力されるかと思います。

```
varresponse=manager.create("YOUR\_APPLICATION1",records);//kintone レコードの生成  
Logger.log('response=\> "%s"', response);  

```

また、最初に共有していただいたコードで試してみましたが、  
自分の環境では、kintoneに回答が正常に反映されました。  
認証情報やkintoneのフィールドの指定などに、間違いがないかを確認してみると良いかもしれません。

---

<div class="post-metadata">

**Author:** ![Legacy\_Account2940](https://avatars.discourse-cdn.com/v4/letter/l/e95f7d/32.png) [@Legacy\_Account2940](https://community.cybozu.dev/u/Legacy_Account2940)\
**Post date:** [2022 年 1 月 19 日午前 3:25 UTC](https://community.cybozu.dev/t/topic/5629/7 "2022-01-19T03:25:19Z")

</div>

重ねてお手間をおかけし恐縮です。

試したところ、同じエラー（TypeError: Cannot read property ‘response’ of undefined）が出てしまいました。

以下、38～44行目の部分です。

> var records = JSON.parse(str);//JSON形式に変換  
> var response = manager.create(“YOUR\_APPLICATION1”, records);//kintone レコードの生成  
> Logger.log(‘response=\> “%s”’, response);  
> // ステータスコード  
> // 成功すれば200になる  
> var code = response.getResponseCode();  
> Logger.log(‘Response code is “%s”’, code);
> 
> よろしくお願いします。

---

<div class="post-metadata">

**Author:** ![Legacy\_Account1384](https://avatars.discourse-cdn.com/v4/letter/l/97f17d/32.png) [@Legacy\_Account1384](https://community.cybozu.dev/u/Legacy_Account1384)\
**Post date:** [2022 年 1 月 19 日午前 6:14 UTC](https://community.cybozu.dev/t/topic/5629/8 "2022-01-19T06:14:46Z")

</div>

TypeError: Cannot read property ‘response’ of undefined は  
`undefined`&nbsp;のプロパティ ‘response’ が読み取れないというエラーなので、  
Google フォームの回答(e) を取得できていないように見えます。

Google Apps Scriptのエディタから直接コードを実行するのではなく、  
記事の「5. プログラムの作成\>Step 12」のトリガーを設定した上で、  
「6. 動作の確認」の通りにフォームの送信を行ったでしょうか。

---

<div class="post-metadata">

**Author:** ![Legacy\_Account2940](https://avatars.discourse-cdn.com/v4/letter/l/e95f7d/32.png) [@Legacy\_Account2940](https://community.cybozu.dev/u/Legacy_Account2940)\
**Post date:** [2022 年 1 月 20 日午前 7:18 UTC](https://community.cybozu.dev/t/topic/5629/9 "2022-01-20T07:18:59Z")

</div>

遅くなりました。フォームからの送信を行い、GASの左側メニューの「実行数」のところを見たところ、以下の記述がありました。

ご確認いただけますでしょうか（一部伏せ字にしています）。

> 2022/01/20 16:13:45
> 
> 情報
> 
> Form submitted
> 
> 2022/01/20 16:13:48
> 
> 情報
> 
> Response JSON is “[{“Email”: { “value”: “●●●●@●●●●.●●.jp” },“文字列\_\_1行\_\_0” : { “value”: “名前テスト” },“文字列\_\_1行\_\_1” : { “value”: “●●テスト” },“文字列\_\_1行\_\_4” : { “value”: “掲載テスト” }}]”
> 
> 2022/01/20 16:13:48
> 
> 情報
> 
> response=\> “{“code”:“CB\_VA01”,“id”:“aUPR3W6ajb5nH7RM1Bbx”,“message”:“入力内容が正しくありません。”,“errors”:{“records[0].日付.value”:{“messages”:[“必須です。”]},“records[0].文字列\_\_1行\_\_6.value”:{“messages”:[“必須です。”]}}}”
> 
> 2022/01/20 16:13:48
> 
> 情報
> 
> Response code is “400.0”

---

<div class="post-metadata">

**Author:** ![Legacy\_Account1384](https://avatars.discourse-cdn.com/v4/letter/l/97f17d/32.png) [@Legacy\_Account1384](https://community.cybozu.dev/u/Legacy_Account1384)\
**Post date:** [2022 年 1 月 20 日午前 7:45 UTC](https://community.cybozu.dev/t/topic/5629/10 "2022-01-20T07:45:56Z")

</div>

> “message”:“入力内容が正しくありません。”,“errors”:{“records[0].日付.value”:{“messages”:[“必須です。”]},“records[0].文字列\_\_1行\_\_6.value”:{“messages”:[“必須です。”]}

エラーメッセージを見る限り、「日付」と「文字列\_\_1行\_\_6」の２つのフィールドはkintone上で必須項目に設定されていますが、  
Googleフォームの項目には含まれていないため、必須項目が空の状態でレコードを登録できず、エラーが出ているように見えます。

「日付」と「文字列\_\_1行\_\_6」フィールドの「必須項目にする」チェックを外す、  
もしくは上記２つのフィールドを、Googleフォームの必須項目として追加するのはいかがでしょうか？

---

<div class="post-metadata">

**Author:** ![Legacy\_Account2940](https://avatars.discourse-cdn.com/v4/letter/l/e95f7d/32.png) [@Legacy\_Account2940](https://community.cybozu.dev/u/Legacy_Account2940)\
**Post date:** [2022 年 1 月 20 日午前 8:00 UTC](https://community.cybozu.dev/t/topic/5629/11 "2022-01-20T08:00:14Z")

</div>

ありがとうございます。ここのエラーはKintone側のものだったのですね。必須項目を外したところ、登録されました！

&nbsp;

ありがとうございました。今回はテストで一部項目のみをGASに書きましたので、日付など残りの項目もフォーム上に追加していきたいと思います。本当にありがとうございました。

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/cybozu/original/1X/d5c841c3c5a6cb66eed514001c1b45147c9e1f4f.png) [@system](https://community.cybozu.dev/u/system)\
**Post date:** [2025 年 5 月 30 日午前 5:47 UTC](https://community.cybozu.dev/t/topic/5629/12 "2025-05-30T05:47:12Z")

</div>

クローズされました: 2025 年 5 月 30 日午前 5:47 UTC

このトピックはベストアンサーに選ばれた返信から 3 日が経過したので自動的にクローズされました。新たに返信することはできません。
