# 関連レコードの情報の有無を取得したい

**URL:** <https://community.cybozu.dev/t/topic/3253>\
**Category:** kintone 開発相談\
**Created:** [2018 年 7 月 30 日午前 10:29 UTC](https://community.cybozu.dev/t/topic/3253 "2018-07-30T10:29:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Legacy\_Account727](https://avatars.discourse-cdn.com/v4/letter/l/97f17d/32.png) [@Legacy\_Account727](https://community.cybozu.dev/u/Legacy_Account727)\
**Post date:** [2018 年 7 月 30 日午前 10:29 UTC](https://community.cybozu.dev/t/topic/3253/1 "2018-07-30T10:29:00Z")

</div>

kintone歴 1か月になります。

質問させていただきます。

&nbsp;

あるアプリのレコード内に関連レコードの情報を置いています。

関連レコードで取得できる情報が１件でもあった場合に、レコード一覧の特定のセルに色をつけるという処理を作りたいと思っています。

（この１件についてはレコードを登録、編集するときに取得して保存済みの情報とします）

&nbsp;

色の付け方はチュートリアル

[https://developer.cybozu.io/hc/ja/articles/202161864](https://developer.cybozu.io/hc/ja/articles/202161864)&nbsp;

でわかりましたが、

&nbsp;

関連レコードの情報の有無の取り方が分かりません。

kintone.events.on(‘app.record.index.show’, function(event) {

&nbsp;

});

&nbsp;

&nbsp;

とした場合event内に関連レコードの要素があると思っていましたが

見当たらず。

取得する方法はなにかないでしょうか？

イベントとしてはshow()の時に実施したいです。

&nbsp;

&nbsp;

お知恵をいただければと思います。よろしくお願いします。

---

<div class="post-metadata">

**Author:** ![Legacy\_Account1740](https://avatars.discourse-cdn.com/v4/letter/l/ed8c4c/32.png) [@Legacy\_Account1740](https://community.cybozu.dev/u/Legacy_Account1740)\
**Post date:** [2018 年 7 月 30 日午前 11:27 UTC](https://community.cybozu.dev/t/topic/3253/2 "2018-07-30T11:27:30Z")

</div>

tanaka-r様

お世話になっております。 cstapの江田と申します。

関連レコードのデータはrecords.jsonを使うなどして、自分で取得しなければなりません。 下記のようなコードで実装できるかと思います。 2ケ所フィールドコードを書くところがあるのでそこは変更してください。

```
(function(){"use strict";kintone.events.on(['app.record.index.show'],function(event){RelatedRecordsFieldManager.prototype.getFieldProperties().then(function(){varrelatedRecordsField=newRelatedRecordsFieldManager('関連レコードのフィールドコード');event.records.forEach(function(record,index){relatedRecordsField.getRecords(record).then(function(records){if(records.length){kintone.app.getFieldElements('色を塗るフィールドのフィールドコード')[index].style.background='#f00';}});});});});varRelatedRecordsFieldManager=(function(fieldCode){functionRelatedRecordsFieldManager(fieldCode){this.fieldCode=fieldCode;this.targetAppId=kintone.app.getRelatedRecordsTargetAppId(fieldCode);this.property=this.fieldProperties[fieldCode].referenceTable;}RelatedRecordsFieldManager.prototype={selfAppId:kintone.app.getId(),records:[],limit:1,//limit: 500,offset:0,getFieldProperties:function(){returnkintone.api(kintone.api.url('/k/v1/app/form/fields',true),'GET',{app:RelatedRecordsFieldManager.prototype.selfAppId,}).then(function(response){RelatedRecordsFieldManager.prototype.fieldProperties=response.properties;});},query:function(record){return(this.property.condition.relatedField+'="'+record[this.property.condition.field].value+(this.property.filterCond?'" and ':'"')+this.property.filterCond);},getRecords:function(record){var\_this=this;returnkintone.api(kintone.api.url('/k/v1/records',true),'GET',{app:this.targetAppId,query:this.query(record)+' order by '+this.property.sort+' limit '+this.limit+' offset '+this.offset}).then(function(response){returnresponse.records;/\*\_this.records = \_this.records.concat(response.records); \_this.offset += response.records.length; if(response.records.length === \_this.limit){ return \_this.getRecords(record); }else{ return \_this.records; }\*/});}}returnRelatedRecordsFieldManager;})();})();

```

---

<div class="post-metadata">

**Author:** ![Legacy\_Account727](https://avatars.discourse-cdn.com/v4/letter/l/97f17d/32.png) [@Legacy\_Account727](https://community.cybozu.dev/u/Legacy_Account727)\
**Post date:** [2018 年 8 月 3 日午前 11:39 UTC](https://community.cybozu.dev/t/topic/3253/3 "2018-08-03T11:39:11Z")

</div>

江田篤史様

初めまして。返答が遅くなり申し訳ありません。

大変ご丁寧な回答をしていただきありがとうございます。

&nbsp;

関連レコードは自分で取得するしかないのですね。

いただいたコードを参考に、実装を進めていってみます。！

内容も理解できるように、時間ととって読み込んでみます。

&nbsp;

ありがとうございます。！

&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:** [2025 年 4 月 25 日午前 6:02 UTC](https://community.cybozu.dev/t/topic/3253/4 "2025-04-25T06:02:29Z")

</div>

クローズされました: 2025 年 4 月 25 日午前 6:02 UTC

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