現在時刻取得したら選択したラジオボタンがリセットされてしまう。

ボタンを押したら現在時刻を取得できるようにkintoneで構築中です。
ボタンを押して現在時刻取得まではできたのですが、
ボタンを押すとすでに選択していたラジオボタンがすべて初期値に戻るという
現象が起きてしまいました。
本来であれば、ボタン押す前に選択しているラジオボタンは選択した位置のままで現在時刻を取得して保存するということなのですが。
作業項目ごとに1つのアプリで作業時刻などを取りたいので、同じコードを作業項目ごとに4つほど重ねて使用してます。それも原因なのでしょうか。
以下はkintoneに構築しているままコピペしておりますので同じコードが4つほど重なっています。

お見苦しいかと思いますが何か改善方法ご存じの方いましたらご教授いただきたいです。

	
/*  現在日時入力ボタン   */
(function() {
    'use strict';

    // 初期設定 フィールドコードとボタンのスペースIDの設定
    const my_field_code = 'Now_datetime';
    const my_space_ID = 'button_space'; 

    // 新規登録と編集画面でイベント発火
    const events = [
        'app.record.create.show',
        'app.record.edit.show'
    ];

    kintone.events.on(events, function(event) {
        const record = event.record;

        // ボタンの作成
        const startButton = document.createElement('button');
        startButton.innerText = '前処理開始';
        startButton.onclick = function() {
            const currentDatetime = new Date().toISOString();
            record[my_field_code].value = currentDatetime;
            kintone.app.record.set(event);
        };

        // ボタンをフォームに追加
        kintone.app.record.getSpaceElement(my_space_ID).appendChild(startButton);

        return event;
    });
})();
/*  現在日時入力ボタン   */
(function() {
    'use strict';

    // 初期設定 フィールドコードとボタンのスペースIDの設定
    const my_field_code = 'Now_datetime2';
    const my_space_ID = 'button_space2'; 

    // 新規登録と編集画面でイベント発火
    const events = [
        'app.record.create.show',
        'app.record.edit.show'
    ];

    kintone.events.on(events, function(event) {
        const record = event.record;

        // ボタンの作成
        const startButton = document.createElement('button');
        startButton.innerText = '前処理終了';
        startButton.onclick = function() {
            const currentDatetime = new Date().toISOString();
            record[my_field_code].value = currentDatetime;
            kintone.app.record.set(event);
        };

        // ボタンをフォームに追加
        kintone.app.record.getSpaceElement(my_space_ID).appendChild(startButton);

        return event;
    });
})();

/*  現在日時入力ボタン   */
(function() {
    'use strict';

    // 初期設定 フィールドコードとボタンのスペースIDの設定
    const my_field_code = 'Now_datetime3';
    const my_space_ID = 'button_space3'; 

    // 新規登録と編集画面でイベント発火
    const events = [
        'app.record.create.show',
        'app.record.edit.show'
    ];

    kintone.events.on(events, function(event) {
        const record = event.record;

        // ボタンの作成
        const startButton = document.createElement('button');
        startButton.innerText = '架電終了';
        startButton.onclick = function() {
            const currentDatetime = new Date().toISOString();
            record[my_field_code].value = currentDatetime;
            kintone.app.record.set(event);
        };

        // ボタンをフォームに追加
        kintone.app.record.getSpaceElement(my_space_ID).appendChild(startButton);

        return event;
    });
})();

/*  現在日時入力ボタン   */
(function() {
    'use strict';

    // 初期設定 フィールドコードとボタンのスペースIDの設定
    const my_field_code = 'Now_datetime4';
    const my_space_ID = 'button_space4'; 

    // 新規登録と編集画面でイベント発火
    const events = [
        'app.record.create.show',
        'app.record.edit.show'
    ];

    kintone.events.on(events, function(event) {
        const record = event.record;

        // ボタンの作成
        const startButton = document.createElement('button');
        startButton.innerText = '後処理終了';
        startButton.onclick = function() {
            const currentDatetime = new Date().toISOString();
            record[my_field_code].value = currentDatetime;
            kintone.app.record.set(event);
        };

        // ボタンをフォームに追加
        kintone.app.record.getSpaceElement(my_space_ID).appendChild(startButton);

        return event;
    });
})();

N.motomuraさん

こんにちは。
onclickの後にレコード値を取得するとどうでしょうか?
レコードの値を取得する - cybozu developer network

イベントが開始した時のeventを返しているので、データがcreate, editの開始の状態から日時データだけ変更しているのをデータをsetしているかなと思います。

このトピックはベストアンサーに選ばれた返信から 3 日が経過したので自動的にクローズされました。新たに返信することはできません。