テーブル内の全レコードの"syear"フィールドに”2021”と更新するロジックを作りたいのですが、
「更新でエラーが発生しました。入力内容がただしくありません。」というエラーが発生します。どうかご教示頂ければ幸いです。
(function() {
“use strict”;
kintone.events.on(‘app.record.detail.show’, function(event) {
var updateAppId = 2;
var paramGet = {
‘app’: updateAppId,
‘id’: kintone.app.record.getId()
};
return kintone.api(kintone.api.url(‘/k/v1/record’, true), ‘GET’, paramGet).then(function(resp) {
var pro = resp.record[“project”].value;
// フィールドの更新
var record = resp.record;
var paramPut = {
‘app’: 2,
‘record’: updateRecords(record,pro)
};
return kintone.api(kintone.api.url(‘/k/v1/record’, true), ‘PUT’, paramPut);
}).then(function(resp2) {
// 処理成功
alert(‘更新が完了しました’);
return event;
}).catch(function(error) {
// エラー表示をする
alert(‘更新でエラーが発生しました。’ + error.message);
return event;
});
function updateRecords(record,pro) {
var tableRecords = record.Table.value;
var putRecords = [];
for (var i = 0, l = tableRecords.length; i < l; i++) {
alert(tableRecords.length);
var tableRecord = tableRecords[i]
var kaishinen = tableRecord.value[‘kaishibi’].value;
putRecords[i] = {“app”: 2,
“id”: kintone.app.record.getId(),
“record”: {
“project”: {
“value”: pro
},
// テーブルの中に配置されているフィールドの1行目の場合
“Table”: {
“value”: [
{
“id”: i,
“value”: {
“syear”: {
“value”: 2021
}
}
}
]
}
},
}
}
return putRecords;
}
});
})();