100件以上のレコードのステータス更新を行いたい

いつもお世話になっています。

 

表題の通り、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);
});


//////////////////////////////////////////クリック時処理終了
        }
    
    });

})();

 

以上、よろしくお願いいたします。

 

一括更新は対応しています。おそらくupdateKeyの必須項目が不足しているのではと思います。

サンプルコードもリンク先にのっているので参考にされると良いかと思います。

https://github.com/kintone/kintoneUtility/blob/master/guides/rest_doc.md#putAllRecords

yukiさんの処理対応は、文章拝見するにステータスフィールドがプロセス管理の設定に伴うもので、/k/v1/records/status.json のAPIによる一括更新を意図されてるのではないでしょうか。 kintoneUtilityは内部的にbulkRequestが利用されていてこれ自体はレコードのステータス一括更新に対応していますが、こちらを見る限り

> https://github.com/kintone/kintoneUtility/blob/master/src/js/rest/common/makeBulkParam.js

kintoneUtilityでは、/k/v1/records/status.json には対応してないということではないでしょうか。エラーメッセージを確認した上で対応進められるとイカと思います(レコード一括更新でレコードのステータス一括更新しようとすると、「ステータスの更新には別のAPIを・・・」みたいなメッセージが出てたような気がします)。