# レコードコメントをフィールドへ入力する方法

**URL:** <https://community.cybozu.dev/t/topic/5209>\
**Category:** kintone 開発相談\
**Created:** [August 26, 2021, 4:48am UTC](https://community.cybozu.dev/t/topic/5209 "2021-08-26T04:48:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Legacy\_Account2672](https://avatars.discourse-cdn.com/v4/letter/l/d26b3c/32.png) [@Legacy\_Account2672](https://community.cybozu.dev/u/Legacy_Account2672)\
**Post date:** [August 26, 2021, 4:48am UTC](https://community.cybozu.dev/t/topic/5209/1 "2021-08-26T04:48:54Z")

</div>

レコードを最終保存する際にレコードコメントをフィールド内、もしくは別アプリに一括保存したいと思っています。

下記URLを参考にレコードコメントを一括取得する段階まではできたのですが、取得したデータをどのようにすれば良いのわからない状態です。

[https://developer.cybozu.io/hc/ja/articles/208242326](https://developer.cybozu.io/hc/ja/articles/208242326)

「変数に代入してデータをPUTすれば良いのかな？」と思ったのですが、変数に代入する段階でエラーが出て先に進めない状態です。

```
function getComments(resp){
const postName=comments[0].creater.name;
const postText=commenst[0].text;
}

```

&nbsp;

「これだとできたとしてもひとつ目のデータしか取得できない？」と自分でも思いつつ、改善策を見つける方法すらわからない状態です。

詳しい方のアドバイスをいただければ幸いです。

---

<div class="post-metadata">

**Author:** ![Legacy\_Account980](https://avatars.discourse-cdn.com/v4/letter/l/a183cd/32.png) [@Legacy\_Account980](https://community.cybozu.dev/u/Legacy_Account980)\
**Post date:** [August 30, 2021, 12:29am UTC](https://community.cybozu.dev/t/topic/5209/2 "2021-08-30T00:29:50Z")

</div>

こんにちは！

＞ レコードコメントを一括取得する段階まではできた

ということで、respに一括取得されたコメントが入っている前提で書きますが

const postName = resp.comments[0].creator.name;

のようにcommentsの前にrespが必要です。（コメントが取得できているなら、respにコメントが入っているはずなので）  
（あと、つづりがcreaterではなくてcreatorですね。）

＞「これだとできたとしてもひとつ目のデータしか取得できない？」  
とのことですが、２つ目は[0]が[1]になります。３つ目は[2]のように取得できます。  
全部の値を取りたいということでしたら、for文やforEachメソッドなどを使うといいと思います。（使い方は検索してみてくださいね）

---

<div class="post-metadata">

**Author:** ![Legacy\_Account2672](https://avatars.discourse-cdn.com/v4/letter/l/d26b3c/32.png) [@Legacy\_Account2672](https://community.cybozu.dev/u/Legacy_Account2672)\
**Post date:** [August 30, 2021, 8:38am UTC](https://community.cybozu.dev/t/topic/5209/3 "2021-08-30T08:38:03Z")

</div>

[juridon様](https://community.cybozu.dev/hc/ja/profiles/376177001012-juridon)

ありがとうございます。

無事に変数に代入できました！これでやっと先に進めます…！

綴り間違いのご指摘もありがとうございます。

for文やforEachメソッドはあまり理解できていないのですが、頑張ってみます！
