お世話になります。
javascriptで、アプリの一覧画面に、プルダウンによるレコード検索を設置しています。
一覧を選択→プルダウンを選択、検索実行用ボタンをクリック→一覧の検索条件に追加して、プルダウンで選択した単語を含むレコードを絞り込む、
という動作をしています。
スクリプト自体は正常に動き、絞込みは正しくかかっているのですが、検索後の一覧名が、検索した値ではなくデフォルトで表示される値に戻ってしまっています。
絞込み値指定のURLにviewIdを追加してみましたが、検索が正しくかかりませんでした。
これを、検索後も、選択した値で固定しておくようにすることはできますでしょうか?
以下、コードです。
(function() {
“use strict”;
kintone.events.on(“app.record.index.show”, function(e){
// プルダウンリストの表示
var id = document.getElementById(‘pulldown’);
if (id == null) {
var sales_offices = [
[111, “項目A”],
[222, “項目B”],
];
var select = document.createElement(‘select’);
select.setAttribute(‘id’, ‘pulldown’);
var option;
var text;
for(var i = 0; i < pulldown.length; i++) {
option = document.createElement(“option”);
option.value = pulldown[i][0];
text = document.createTextNode(pulldown[i][1]);
option.appendChild(text);
select.appendChild(option);
}
kintone.app.getHeaderMenuSpaceElement().appendChild(select);
};
var search_button = document.createElement(‘button’);
search_button.id = ‘search_button’;
search_button.innerHTML = ‘検索’;
search_button.onclick = function () {
var field_pull = “プルダウン検索項目”;
var id = document.getElementById(‘pulldown’);
var index = id.selectedIndex;
var selecttext = id.options[index].value;
var viewid = e.viewId
// var condition = kintone.app.getQueryCondition();
var currentQuery = kintone.app.getQuery();
var str_query = “”;
if (selecttext !== “”) {
var currentQuery_res = currentQuery.match(/(.+) order by(.+)/);
// 前回検索条件を削除
if ( currentQuery_res == null ) {
var addQuery = field_pull + ’ = “’ + selecttext + '”‘;
str_query =’?query=’ + addQuery + ’ ’ + currentQuery;
} else if ( currentQuery_res.length == 3 ) {
var regExp = new RegExp(’ and ’ + field_pull + ’ = “.+”‘, “g” ) ;
var condition_1 = currentQuery_res[1].replace(regExp, “”);
// 追加する検索条件
var addQuery = ’ and ’ + field_pull + ’ = "’ + selecttext + ‘"’;
str_query =‘?query=’+ condition_1 + addQuery + ’ order by’ + currentQuery_res[2];
}
}
document.location = location.origin + location.pathname + str_query;
};
kintone.app.getHeaderMenuSpaceElement().appendChild(search_button);
});
})();