# レコード一覧の背景色が変わらない

**URL:** https://community.cybozu.dev/t/topic/5247
**Category:** kintone 開発相談
**Created:** [2021 年 9 月 6 日午前 8:17 UTC](https://community.cybozu.dev/t/topic/5247 "2021-09-06T08:17:48Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Legacy\_Account364](https://avatars.discourse-cdn.com/v4/letter/l/85e7bf/32.png) [@Legacy\_Account364](https://community.cybozu.dev/u/Legacy_Account364)
#### Post date: [2021 年 9 月 6 日午前 8:17 UTC](https://community.cybozu.dev/t/topic/5247/1 "2021-09-06T08:17:48Z")

</div>

下記JavaScriptで条件を満たしたレコードの背景が変わりません。

＜スクリプト＞

(function () {  
“use strict”;

// 返還日が入力されている場合、当該レコードの背景色を赤色にする。  
const events = [  
‘app.record.index.show’  
];

kintone.events.on(events, function (event) {  
// レコード一行のクラス  
var line = document.getElementsByClassName(“recordlist-row-gaia”)

for (var i = 0; i \< line.length; i++) {  
if (event.records[i][‘henkanbi’][‘value’] === “7/24期限切れ処分”) {  
line[i].style.backgroundcolor = “#ff0000”;  
}  
}  
});

})();

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

line[i].style.backgroundcolor に &nbsp;“#ff0000” がセットされているのは確認したのですが。

---

<div class="post-metadata">

### Author: ![Legacy\_Account1072](https://avatars.discourse-cdn.com/v4/letter/l/b9e5f3/32.png) [@Legacy\_Account1072](https://community.cybozu.dev/u/Legacy_Account1072)
#### Post date: [2021 年 9 月 7 日午前 2:31 UTC](https://community.cybozu.dev/t/topic/5247/2 "2021-09-07T02:31:40Z")

</div>

直接のDOM操作は公式でサポート対象外とされているので、  
用意されている[kintone.app.getFieldElements(フィールドコード)](https://community.cybozu.dev/hc/ja/articles/202341944-%E3%83%AC%E3%82%B3%E3%83%BC%E3%83%89%E4%B8%80%E8%A6%A7%E3%81%A8%E3%83%AC%E3%82%B3%E3%83%BC%E3%83%89%E8%A9%B3%E7%B4%B0%E7%94%BB%E9%9D%A2%E3%81%A7%E6%9D%A1%E4%BB%B6%E6%9B%B8%E5%BC%8F%E3%82%92%E8%A8%AD%E5%AE%9A%E3%81%99%E3%82%8B)を使用することをお勧めします。

背景色の変更は以下のようになります。

```
element.style.backgroundColor = 'xxxx';

```

大まかな流れ

```
const elements = kintone.app.getFieldElements('henkanbi');
event.records.forEach((record,i)=>{
if(record.henkanbi.value == '7/24期限切れ処分'){
elements[i].style.backgroundColor = '#ff0000';
}
});

```

event.recordsと取得したelementsの配列の位置は同じなので、  
event.recordsのforで条件一致した場合にその配列のインデックスiの位置で  
背景色を指定という流れになるかと思います。

条件書式プラグインというものもあります。

&nbsp;

---

<div class="post-metadata">

### Author: ![Legacy\_Account1072](https://avatars.discourse-cdn.com/v4/letter/l/b9e5f3/32.png) [@Legacy\_Account1072](https://community.cybozu.dev/u/Legacy_Account1072)
#### Post date: [2021 年 9 月 7 日午前 2:59 UTC](https://community.cybozu.dev/t/topic/5247/3 "2021-09-07T02:59:33Z")

</div>

追記：  
添付画像にドメインが記載してありますので、  
画像のみ削除をお勧めします。

---

<div class="post-metadata">

### Author: ![Legacy\_Account364](https://avatars.discourse-cdn.com/v4/letter/l/85e7bf/32.png) [@Legacy\_Account364](https://community.cybozu.dev/u/Legacy_Account364)
#### Post date: [2021 年 9 月 7 日午前 5:15 UTC](https://community.cybozu.dev/t/topic/5247/4 "2021-09-07T05:15:52Z")

</div>

岡崎様 ありがとうございます。背景色設定出来ました。

あわせてドメイン記載の件、ご忠告ありがとうございました。
