# ボタンを押したらテーブルのルックアップが更新されるようにしたい

**URL:** <https://community.cybozu.dev/t/topic/113>\
**Category:** kintone 開発相談\
**Created:** [2022 年 9 月 28 日午前 2:35 UTC](https://community.cybozu.dev/t/topic/113 "2022-09-28T02:35:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Legacy\_Account831](https://avatars.discourse-cdn.com/v4/letter/l/9de053/32.png) [@Legacy\_Account831](https://community.cybozu.dev/u/Legacy_Account831)\
**Post date:** [2022 年 9 月 28 日午前 2:35 UTC](https://community.cybozu.dev/t/topic/113/1 "2022-09-28T02:35:39Z")

</div>

&nbsp;JavaScript初心者です。  
こちらのサイトで色々勉強しながらカスタマイズをしているのですが、  
今回どうしてもうまく動作しないのでどなたかご教授頂ければ幸いです。

**【背景・実現したいこと】**  
レコードの詳細画面にボタンを設置し、ボタンをおしたらテーブルのルックアップを一括で  
取得するようにしたい。テーブルの行数が多い為、1つ1つ取得ボタンを押すのが大変な為実現したいです。

編集画面を開いたら一括で取得というのはできたのですが、ルックアップを更新したい場合とそうでない場合があるのでボタンを押すと取得という形にしたいです。

&nbsp;

**【利用したソースコード】**

(function() {  
&nbsp; &nbsp; ‘use strict’;  
&nbsp; &nbsp; kintone.events.on(‘app.record.edit.show’, function(event) {  
&nbsp; &nbsp;&nbsp;  
&nbsp; &nbsp; const mySpaceFieldButton = document.createElement(‘button’);  
&nbsp; &nbsp; mySpaceFieldButton.id = ‘my\_space\_field\_button’;  
&nbsp; &nbsp; mySpaceFieldButton.innerText = ‘ルックアップ更新’;  
&nbsp; &nbsp; mySpaceFieldButton.onclick = () =\> {  
&nbsp; &nbsp; &nbsp;  
&nbsp; &nbsp; &nbsp; var record = event.record;  
&nbsp; &nbsp; &nbsp; for (var i = 0; i \< record[‘items’].value.length; i++) {  
&nbsp; &nbsp; &nbsp; &nbsp; record[‘items’].value[i].value[‘ID’].lookup = true;  
&nbsp; &nbsp; &nbsp; };  
&nbsp; &nbsp; &nbsp; return event;  
&nbsp; &nbsp; };  
&nbsp; &nbsp;&nbsp;  
&nbsp; &nbsp; kintone.app.record.getSpaceElement(‘my\_space\_field\_button’).appendChild(mySpaceFieldButton);&nbsp;

&nbsp; &nbsp; });  
&nbsp; })();

&nbsp;

---

<div class="post-metadata">

**Author:** ![Legacy\_Account1177](https://avatars.discourse-cdn.com/v4/letter/l/77aa72/32.png) [@Legacy\_Account1177](https://community.cybozu.dev/u/Legacy_Account1177)\
**Post date:** [2022 年 9 月 28 日午前 6:24 UTC](https://community.cybozu.dev/t/topic/113/2 "2022-09-28T06:24:29Z")

</div>

ボタン押下時のイベントの場合、event.recordが使えないためkintone.app.record.get()とkintone.app.record.set()が必要になります。

```
mySpaceFieldButton.onclick = () => {
    let recordData = kintone.app.record.get(), rec = recordData.record;

  for (let i = 0; i < rec['items'].value.length; i++) {
      rec['items'].value[i].value['ID'].lookup = true;
  };

    kintone.app.record.set(recordData);
};

```

&nbsp;

---

<div class="post-metadata">

**Author:** ![Legacy\_Account831](https://avatars.discourse-cdn.com/v4/letter/l/9de053/32.png) [@Legacy\_Account831](https://community.cybozu.dev/u/Legacy_Account831)\
**Post date:** [2022 年 9 月 28 日午前 7:59 UTC](https://community.cybozu.dev/t/topic/113/3 "2022-09-28T07:59:30Z")

</div>

ご教授頂きありがとうございます！  
頂いたコードに変更して望み通りの動きを実行することが出来ました。  
ボタン押下時はevent.recordが使えないのですね。勉強不足で申し訳ありません。

ずっと悩んでいたのでとても助かりました！ありがとうございました。

&nbsp;

---

<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:** [2024 年 6 月 6 日午前 4:19 UTC](https://community.cybozu.dev/t/topic/113/4 "2024-06-06T04:19:46Z")

</div>

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