Problem
When running the following queries multiple times in a row within Kintone to get records, the result at times differ.
種別 in ("新規") and HC名 = "QG" and 作業中 >= LAST_MONTH() and 作業完了 = "" and キャンセル有無 = "0" and 作業中 <= THIS_MONTH(LAST) order by レコード番号 desc limit 500 offset 0
種別 in ("リピーター") and HC名 = "QG" and 作業完了 >= LAST_MONTH() order by レコード番号 desc limit 500 offset 0
種別 in ("リピーター") and HC名 = "QG" and 見積依頼 >= LAST_MONTH() order by レコード番号 desc limit 500 offset 0
種別 in ("リピーター") and HC名 = "QG" and 作業中 >= LAST_MONTH() and 作業完了 = "" and キャンセル有無 = "0" and 作業中 <= THIS_MONTH(LAST) order by レコード番号 desc limit 500 offset 0
種別 in ("新規") and HC名 = "QG" and 作業完了 = LAST_YEAR() order by レコード番号 desc limit 500 offset 0
種別 in ("新規") and HC名 = "QG" and 見積依頼 = LAST_YEAR() order by レコード番号 desc limit 500 offset 0
種別 in ("リピーター") and HC名 = "QG" and 作業完了 = LAST_YEAR() order by レコード番号 desc limit 500 offset 0
種別 in ("リピーター") and HC名 = "QG" and 見積依頼 = LAST_YEAR() order by レコード番号 desc limit 500 offset 0
Reproduce the bug
Please follow the following steps to reproduce this bug:
- Paste the following JS code in the console of this page.
- Try to run
test()
method then press enter key many times.
You will see that for some time, Kintone return the incorrect total count and caused user’s bug.
Like the attached picture:
async function test() {
let queryList = [
'種別 in ("新規") and HC名 = "QG" and 作業中 >= LAST_MONTH() and 作業完了 = "" and キャンセル有無 = "0" and 作業中 <= THIS_MONTH(LAST) order by レコード番号 desc limit 500 offset 0',
'種別 in ("リピーター") and HC名 = "QG" and 作業完了 >= LAST_MONTH() order by レコード番号 desc limit 500 offset 0',
'種別 in ("リピーター") and HC名 = "QG" and 見積依頼 >= LAST_MONTH() order by レコード番号 desc limit 500 offset 0',
'種別 in ("リピーター") and HC名 = "QG" and 作業中 >= LAST_MONTH() and 作業完了 = "" and キャンセル有無 = "0" and 作業中 <= THIS_MONTH(LAST) order by レコード番号 desc limit 500 offset 0',
'種別 in ("新規") and HC名 = "QG" and 作業完了 = LAST_YEAR() order by レコード番号 desc limit 500 offset 0',
'種別 in ("新規") and HC名 = "QG" and 見積依頼 = LAST_YEAR() order by レコード番号 desc limit 500 offset 0',
'種別 in ("リピーター") and HC名 = "QG" and 作業完了 = LAST_YEAR() order by レコード番号 desc limit 500 offset 0',
'種別 in ("リピーター") and HC名 = "QG" and 見積依頼 = LAST_YEAR() order by レコード番号 desc limit 500 offset 0',
];
let tasks = queryList.map(r => {
return query(r);
});
let result = [];
let sum = 0;
for (let i = 0; i < tasks.length; i++) {
let r = await tasks[i];
result.push(r);
sum += parseInt(r.toString());
}
console.log(sum);
console.log(result);
}
async function query(query) {
return new Promise((resolve, reject) => {
const body = {
'app': 5679,
'query': query,
'fields': ['HC支店名', 'HC支店番号', '見積依頼'],
totalCount: true
};
kintone.api(kintone.api.url('/k/v1/records', true), 'GET', body, function (resp) {
// success
resolve(resp.totalCount);
}, function (error) {
// error
console.log(error);
});
});
}