const script = document.createElement("script");
"https://unpkg.com/@kintone/rest-api-client@2.0.27/umd/KintoneRestAPIClient.min.js";
document.body.appendChild(script);
const minCapa = 1000000; // 1MB未満は表示しない
// const minCapa = 10000000; // 10MB未満は表示しない
// const minCapa = 100000000; // 100MB未満は表示しない
// レコード数が多い場合はこのconditionの内容を変更してください
const condition = "$id >= 1 and $id <= 10000";
// const condition = "$id >= 10001 and $id <= 20000";
// const condition = "$id >= 20001 and $id <= 30000";
const idKey = "__レコード番号__";
const totalKey = "__合計__";
const client = new KintoneRestAPIClient();
const app = kintone.app.getId();
const { properties } = await client.app.getFormFields({ app });
const fileFields = Object.values(properties)
.filter(({ type }) => type === "FILE")
.map(({ code }) => code);
const tableFileFields = Object.values(properties)
.filter(({ type }) => type === "SUBTABLE")
.reduce((acc, { code: tableCode, fields }) => {
const codes = Object.values(fields)
.filter(({ type }) => type === "FILE")
.map(({ code }) => code);
return { ...acc, [tableCode]: codes };
fileFields.length === 0 &&
Object.values(tableFileFields).flat().length === 0
console.log("添付ファイルフィールドが存在しません。");
const records = await client.record.getAllRecords({
fields: fileFields.concat(Object.keys(tableFileFields)),
const totalizeFileSize = (a, b) => a + parseInt(b.size, 10);
const volumes = records.map((record) => {
for (const fileField of fileFields) {
volume[fileField] = record[fileField].value.reduce(totalizeFileSize, 0);
for (const tableFileField of Object.keys(tableFileFields)) {
for (const fileField of tableFileFields[tableFileField]) {
for (const row of record[tableFileField].value) {
volume[fileField] += row.value[fileField].value.reduce(
const total = Object.values(volume).reduce((a, b) => a + b);
// 添付ファイルフィールドの容量は出力しない場合
// return { [idKey]: record.$id.value, [totalKey]: total };
return { [idKey]: record.$id.value, [totalKey]: total, ...volume };
const overVolumes = volumes.filter((volume) => volume[totalKey] > minCapa);
overVolumes.sort((a, b) => a[totalKey] - b[totalKey]);
for (const overVolume of overVolumes) {
overVolume[totalKey] = Number(overVolume[totalKey]).toLocaleString();
console.info(...overVolumes);