# ドロップダウンの値によって非表示

**URL:** <https://community.cybozu.dev/t/topic/1505>\
**Category:** kintone 開発相談\
**Created:** [2023 年 4 月 5 日午後 11:25 UTC](https://community.cybozu.dev/t/topic/1505 "2023-04-05T23:25:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Legacy\_Account293](https://avatars.discourse-cdn.com/v4/letter/l/ecc23a/32.png) [@Legacy\_Account293](https://community.cybozu.dev/u/Legacy_Account293)\
**Post date:** [2023 年 4 月 5 日午後 11:25 UTC](https://community.cybozu.dev/t/topic/1505/1 "2023-04-05T23:25:06Z")

</div>

**背景・実現したいこと**

&nbsp;LBY契約商材がプロバイダ 可変/保守を選択した時のみプロバイダ会社/プロバイダプランを表示するようにしたいのですが、下記ソースですと、選択しても表示されません。

どこを修正すればいいでしょうか？

**エラー情報** （開発者ツールのコンソール）

&nbsp;

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

&nbsp;

(function() {  
&nbsp; ‘use strict’;

&nbsp; &nbsp;var events1 = [  
&nbsp; &nbsp; ‘app.record.create.show’, &nbsp; &nbsp;  
&nbsp; &nbsp; ‘app.record.create.change.LBY契約商材’, &nbsp; &nbsp;  
&nbsp; &nbsp; ‘app.record.edit.show’,  
&nbsp; &nbsp; ‘app.record.edit.change.LBY契約商材’,  
&nbsp; &nbsp; ‘app.record.detail.show’,  
&nbsp; &nbsp;];

&nbsp; &nbsp; kintone.events.on(events1, function(event) {

&nbsp; &nbsp; kintone.app.record.setFieldShown(‘プロバイダ会社’, false);  
&nbsp; &nbsp; kintone.app.record.setFieldShown(‘プロバイダプラン’, false);

&nbsp; &nbsp; var record = event.record[‘LBY契約商材’].value;

&nbsp; &nbsp; switch (record) {  
&nbsp; &nbsp; &nbsp; case ‘プロバイダ 可変/保守’ :  
&nbsp; &nbsp; &nbsp; &nbsp; kintone.app.record.setFieldShown(‘プロバイダ会社’, true);  
&nbsp; &nbsp; kintone.app.record.setFieldShown(‘プロバイダプラン’, true);  
break;  
}  
&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:** [2023 年 4 月 6 日午前 12:47 UTC](https://community.cybozu.dev/t/topic/1505/2 "2023-04-06T00:47:57Z")

</div>

```
   var events1 = [
    'app.record.create.show',    
    'app.record.create.change.LBY契約商材',    
    'app.record.edit.show',
    'app.record.edit.change.LBY契約商材',
    'app.record.detail.show',
   ];
// 略
   var record = event.record['LBY契約商材'].value;

```

↓

```
 var events1 = [
  'app.record.create.change.LBY契約商材',    
  'app.record.edit.change.LBY契約商材',
   ];
   // 略
 var record = event.changes.row.value['LBY契約商材'].value;

```

サブテーブル上のフィールドはevent.record.フィールドコード.valueとは指定方法が異なります。サブテーブルは値が配列になるので、ループで処理をさせるか、event.changes.rowまたはevent.changes.fieldを使うと良いでしょう（[参考](https://cybozu.dev/ja/kintone/docs/js-api/events/create/create-change-event/#properties-of-the-event-object)）。

ただし、これらはchangeイベントのみで使用できるものなので、showイベントでも同様に指定する場合はサブテーブルのループを回すか、[find()](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/find)等を使うか、工夫が必要です。

---

<div class="post-metadata">

**Author:** ![Legacy\_Account293](https://avatars.discourse-cdn.com/v4/letter/l/ecc23a/32.png) [@Legacy\_Account293](https://community.cybozu.dev/u/Legacy_Account293)\
**Post date:** [2023 年 4 月 6 日午前 6:08 UTC](https://community.cybozu.dev/t/topic/1505/3 "2023-04-06T06:08:56Z")

</div>

回答ありがとうございます。

下記ソースに変更致しましたが、表示されません。

どこを修正すればいいでしょうか？

&nbsp;

&nbsp;

&nbsp;

(function() {  
&nbsp; ‘use strict’;

&nbsp; &nbsp;var events1 = [  
&nbsp; &nbsp; ‘app.record.create.change.LBY契約商材’, &nbsp; &nbsp;  
&nbsp; &nbsp; ‘app.record.edit.change.LBY契約商材’,  
&nbsp; &nbsp;];  
&nbsp; &nbsp;

&nbsp; &nbsp; kintone.events.on(events1, function(event) {

&nbsp; &nbsp; kintone.app.record.setFieldShown(‘プロバイダ会社’, false);  
&nbsp; &nbsp; kintone.app.record.setFieldShown(‘プロバイダプラン’, false);  
&nbsp; &nbsp; var record = event.changes.field.value[‘LBY契約商材’].value;

&nbsp; &nbsp; switch (record) {  
&nbsp; &nbsp; &nbsp; case ‘プロバイダ 可変/保守’ :  
&nbsp; &nbsp; &nbsp; &nbsp; kintone.app.record.setFieldShown(‘プロバイダ会社’, true);  
&nbsp; &nbsp; kintone.app.record.setFieldShown(‘プロバイダプラン’, true);  
break;  
}  
&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:** [2023 年 4 月 6 日午前 6:16 UTC](https://community.cybozu.dev/t/topic/1505/4 "2023-04-06T06:16:32Z")

</div>

唐木陽平 さま

```
    var record = event.changes.field.value['LBY契約商材'].value;

```

↓

```
  var record = event.changes.field.value;

```

この場合のfieldは変更したフィールドなので、フィールドコードは必要ありません。個人的にはevent.changes.row.value[‘LBY契約商材’].valueとすることをおすすめします。

&nbsp;

もう一点追加ですが、

```
 break;
    }
  });

```

↓

```
 break;
    }

return event;
  });

```

イベントの終わりにはreturn eventをする癖をつけておくことを推奨します。このカスタマイズ自体には影響しない（仮にフィールドの中身を書き換えるようなカスタマイズの場合は必須）ものの、今後同じイベントを使った別のカスタマイズをした際に、そのカスタマイズが動作しなくなります。

---

<div class="post-metadata">

**Author:** ![Legacy\_Account293](https://avatars.discourse-cdn.com/v4/letter/l/ecc23a/32.png) [@Legacy\_Account293](https://community.cybozu.dev/u/Legacy_Account293)\
**Post date:** [2023 年 4 月 6 日午前 6:24 UTC](https://community.cybozu.dev/t/topic/1505/5 "2023-04-06T06:24:49Z")

</div>

&nbsp; break;  
}  
return event;  
&nbsp; });

に変更した場合、一番上の

(function() {

にエラー Unmatched’ {'.

と出るのですが、どのように修正すればいいでしょうか？何度もすみません

---

<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:** [2023 年 4 月 6 日午前 8:10 UTC](https://community.cybozu.dev/t/topic/1505/6 "2023-04-06T08:10:31Z")

</div>

唐木陽平 さま

括弧が正しく閉じられていないエラーですね。最終行の

```
})();

```

は残っていますか？

---

<div class="post-metadata">

**Author:** ![Legacy\_Account293](https://avatars.discourse-cdn.com/v4/letter/l/ecc23a/32.png) [@Legacy\_Account293](https://community.cybozu.dev/u/Legacy_Account293)\
**Post date:** [2023 年 4 月 6 日午前 8:38 UTC](https://community.cybozu.dev/t/topic/1505/7 "2023-04-06T08:38:02Z")

</div>

抜けてました！

設定出来ました、本当にありがとうございました！！

&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:** [2023 年 10 月 6 日午前 2:44 UTC](https://community.cybozu.dev/t/topic/1505/8 "2023-10-06T02:44:32Z")

</div>

クローズされました: 2023 年 10 月 6 日午前 2:44 UTC

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