見た限り、以下4点が気になりました。
①
「チェックボックスを選択または外した時」というタイミングであればapp.record.create.change.check及びapp.record.edit.change.checkがイベントになります(ご提示されたコードのdetail.show create.show edit.showはそれぞれレコード閲覧画面、新規作成画面、編集画面を開いた時というイベントです)。
②
チェックボックスや複数選択等、複数選択できるものの値は「配列」というものになります。ご提示されたコードだと比較ができません。
// ①(型を含む比較:===から型を含まない比較:==に変更 ○の他に更に選択した場合不一致になるため非推奨)
record.check.value == '〇'
// ②(〇が含まれているかの判定)
record.check.value.includes('〇')
// ③(〇が含まれているかの判定)
record.check.value.indexOf('〇') !== -1
// ④(中身は問わずにチェックされているかどうかだけの判定)
record.check.value.length
こういった形にする必要があります(②が現在の主流なので、そちらだけ覚えれば問題ありません)。
③
kintoneの日時フィールドは「YYYY-MM-DDTHH:mm(ゼロ詰め必須)」という形で、new Date()だけではできません。
Day.jsやLuxon等の日付操作ライブラリを入れるのが手軽ですが、どちらも使わない場合
const now = new Date();
const year = now.getFullYear();
const month = `0${now.getMonth() + 1}`.slice(-2);
const date = `0${now.getDate()}`.slice(-2);
const hour = `0${now.getHours()}`.slice(-2);
const min = `0${now.getMinutes()}`.slice(-2);
const nowTime = `${year}-${month}-${date}T${hour}:${min}`;
このような形になります。
④
フィールドに反映させるためにはreturn event;が必要です。
以下のような形になります。
(() => {
'use strict';
const events = [
'app.record.create.change.check', 'app.record.edit.change.check'
];
kintone.events.on(events, (event) => {
const record = event.record;
const now = new Date();
const year = now.getFullYear();
const month = `0${now.getMonth() + 1}`.slice(-2);
const date = `0${now.getDate()}`.slice(-2);
const hour = `0${now.getHours()}`.slice(-2);
const min = `0${now.getMinutes()}`.slice(-2);
const nowTime = `${year}-${month}-${date}T${hour}:${min}`;
if (record.check.value.includes('〇')) {
record.daytime.value = nowTime;
} else {
record.daytime.value = '';
}
return event;
});
})();