いつもお世話になっています。
表題の通り、100件以上(具体的には3000件程度)のレコードのステータス更新を行いたいと思っています。
ステータスのフローは未処理→承認で、実行ユーザーの指定はありません。
kintone Utility Library for javascriptを利用して行おうと思ったのですが、うまくいきません。ステータス更新には対応していないのでしょうか?
対応していない場合、他の実装方法はあるのでしょうか。
以下、サンプルコードです。
(function() {
"use strict";
// レコード一覧画面
kintone.events.on('app.record.index.show', function(event) {
var appId = kintone.app.getId();
if (event.viewId !== 5359747) {
return;
}
// 増殖バグを防ぐ
if (document.getElementById('balusButton') !== null) {
return;
}
var statusButtun = document.createElement('button');
statusButtun.id = 'balusButton';
statusButtun.innerHTML = '一括承認';
// ボタンクリック時の処理
statusButtun.onclick = function() {
updatestatusValue();
};
kintone.app.getHeaderMenuSpaceElement().appendChild(statusButtun);
return event;
/////////////////////////////////////////////////////クリック時処理開始
function updatestatusValue() {
///////////////////////////////////////////////////全レコード取得
var param = {
app: event.appId,
query: '変更対象 in ("変更対象")',
fields: ['$id','ステータス'],
totalCount: true,
isGuest: false
};
kintoneUtility.rest.getRecords(param).then(function(resp) {
//////////////////////////////////////////////////// 全レコード更新
if (resp.totalCount > 0) {
swal({
title: 'ステータスを更新します',
text: '更新対象レコード ' + resp.totalCount + ' 件',
type: 'success',
showCancelButton: true,
closeOnConfirm: false,
showLoaderOnConfirm: true,
}, function() {
var param = {
app: event.appId,
query: '変更対象 in ("変更対象")',
fields: ['$id','ステータス'],
totalCount: false,
isGuest: false
};
kintoneUtility.rest.getAllRecordsByQuery(param).then(function(resp) {
var rec = event.records;
var records = [];
for ( var h in rec ) {
var obj = {};
console.log(rec[h]["ステータス"]);
if ( rec[h]["ステータス"].value === "未処理" ) {
obj["id"] = rec[h].$id.value;
obj["action"] = "承認";
records.push(obj);
console.log(obj);
}
}
var param = {
app: event.appId,
records: records,
// records: newRecords,
isGuest: false
};
kintoneUtility.rest.putAllRecords(param).then(function(resp) {
//////////////////////////////////////////更新処理完了
console.log(JSON.stringify(resp, null, ' '));
swal({
title: '更新完了!',
text: records.length + ' レコード更新しました',
type: 'success',
}, function(resp) {
location.reload();
});
}).catch(function(error) {
// 更新エラー処理
sweetAlert("レコード更新エラー!", error.message, "error");
console.log(error.message);
});
}).catch(function(error) {
// エラー時の処理
sweetAlert("レコード取得エラー!", error.message, "error");
});
});
}
else {
swal('更新対象レコードがありません!');
}
//////////////////////////////////////////取得時処理終了
}).catch(function(error) {
sweetAlert("レコード取得エラー!", error.message, "error");
console.log(error.message);
});
//////////////////////////////////////////クリック時処理終了
}
});
})();
以上、よろしくお願いいたします。