I want to use a checkbox to record the number value, and then when I click the checkbox, it records all the values in the checkbox and shows them in the sum text box.
Hello @Weerapat_Tangkanakul
Here's an example script:
(function() {
'use strict';
// Field codes
const CHECKBOX_FIELD = 'Checkbox'; // Checkbox field
const RESULT_FIELD = 'Sum'; // Field to display the sum
const events = [
'app.record.create.change.' + CHECKBOX_FIELD,
'app.record.edit.change.' + CHECKBOX_FIELD,
'app.record.create.show',
'app.record.edit.show'
];
kintone.events.on(events, function(event) {
const record = event.record;
const selectedValues = record[CHECKBOX_FIELD].value;
let total = 0;
selectedValues.forEach(value => {
const number = Number(value);
if (!isNaN(number)) {
total += number;
}
});
record[RESULT_FIELD].value = total;
return event;
});
})();