背景・実現したいこと
日時フィールドでの絞込を行いたいです。
日付の入力をしてボタン押下すると、その日付のレコードだけを絞込する機能を実現したいです。
現在、入力日付の0時から入力日付+1日の0時までのレコードを出そうとしています。
ですが、実行すると入力日付+1日の10時 のレコード等が一緒に出てきてしまいます。
ご教授いただければ幸いです。
※念の為、アプリIDとビューIDを「?」にしています。
利用したソースコード
//レコード一覧表示のイベントハンドラー
(function () {
'use strict';
//検索したいフィールドの設定値
const TAIOUNICHIJI = '対応日時';
const SAKUSEISHA = '作成者';
//一覧画面のViewID
const VIEW_ID = ??????;
//日時取得
const date = new Date();
const dateMoment = moment(date, "YYYY-MM-DD");
const today = dateMoment.format('YYYY-MM-DD');
kintone.events.on("app.record.index.show", function (event) {
moment.locale('ja');
//日付検索キーワード
const search_word = document.createElement('input');
search_word.type = 'date';
search_word.value = today;
//検索ボタン
const search_button = document.createElement('input');
search_button.type = 'submit';
search_button.value = '日報通知する';
//キーワード検索の関数
function keyword_search() {
const viewpath = '?view=' + VIEW_ID;
const searchDateStart = moment(search_word.value).format('YYYY-MM-DD');
const searchDateEnd = moment(search_word.value).add(1, 'days').format('YYYY-MM-DD');
const loginUser = kintone.getLoginUser();
const loginUserCode = loginUser.code;
let str_query;
if (search_word.value === "") {
str_query = "";
} else if (search_word.value !== "") {
str_query = '&query=' +
TAIOUNICHIJI + ' = "' + searchDateStart + '" and ' +
TAIOUNICHIJI + ' <= "' + searchDateEnd + '" and ' +
SAKUSEISHA + ' in (' + loginUserCode + ')';
}
//検索結果のURLを返す
const searchResult = location.origin + location.pathname + viewpath + str_query;
return searchResult;
}
// 通知登録関数
function tsuchiToroku(url) {
// 通知アプリのID
const appId = ???;
//URL登録
const body = {
app: appId,
record: {
'日報URL': {
value: url
}
}
};
// 通知アプリに record 登録
kintone.api(kintone.api.url('/k/v1/record', true), 'POST', body);
}
//通知ボタン押下時の動作
search_button.onclick = function () {
//URL生成、エンドーディング
const tsuchiUrl = encodeURI(keyword_search());
//通知登録関数を実行
tsuchiToroku(tsuchiUrl);
//自分の日報一覧へ飛ぶ
document.location.href = tsuchiUrl;
};
//重複を避けるため要素をあらかじめクリアしておく
const node_space = kintone.app.getHeaderMenuSpaceElement();
for (var i = node_space.childNodes.length - 1; i >= 0; i--) {
node_space.removeChild(node_space.childNodes[i]);
}
//ボタン配置
const label = document.createElement('label');
label.appendChild(document.createTextNode('通知日付'));
label.appendChild(document.createTextNode(' '));
label.appendChild(search_word);
label.appendChild(document.createTextNode(' '));
label.appendChild(search_button);
kintone.app.getHeaderMenuSpaceElement().appendChild(label);
return event;
});
})();