How do I sum blank values?

Hi all Dev teams. Have a nice day. so,

I want to add values that are left blank, the idea is to check = [-----] values. but in doing so, values like: V.I.P and normal don’t work. help me refine the code below.

 

(function () {
"use strict";
kintone.events.on(['app.record.create.submit', 'app.record.edit.submit', "app.record.edit.show", 'app.record.detail.show'], function (event) {
var record = event.record;

var subTotals = new Array();
var tableRecords = event.record.table.value;


for (var i = 0; i < tableRecords.length; i++) {
var category = tableRecords[i].value['typeab'].value;
if (!subTotals[category]) {
subTotals[category] = 0;
}
var price = tableRecords[i].value['price1'].value;
subTotals[category] -= -1 * price;
}
//choose blank case (dropdown)
var sum_bara = 0;
//choose normal case (dropdown)
var sum_barb = 0;
//choose V.I.P case (dropdown)
var sum_barc = 0;

event.record.blank.disabled = true;
event.record.normal.disabled = true;
event.record.V.I.P.disabled = true;

sum_bara += subTotals['-----']; //how i can to get value here? this is right? or subTotals['undefined']
sum_barb += subTotals['normal'];
sum_barc += subTotals['V.I.P'];

if (event.type === 'app.record.create.submit' || event.type === 'app.record.edit.submit') {
record.blank.value = sum_bara;
record.normal.value = sum_barb;
record.V.I.P.value = sum_barc;
}
return event;
});
})();

Hi NDC,

I was unsure what the question was here, but did you want to set the value of subTotals to a variable such as sum_bara?

SubTotals is defined as an array, as shown in the following process.

var subTotals = new Array();

Since JavaScript arrays are supposed to be indexed by numbers starting from 0,
it is possible to get the value by specifying a character, as shown below.

subTotals['undefined']
subTotals['normal']
subTotals['V.I.P']

However, it also looks like you want to change ‘undefined’ to a numeric value,
so could you please confirm the details of what you want to do?

Also, since it seems that you are manipulating the values in the table,
I would like to know what values are set in each field that affects the process,
such as the “typeab” field and the “price1” field, as well as sample data and the expected results.

 

Thanks

Hi Sean Tachibana,

Sorry my english not good.

I want to sum the same values and display them in the textbox. The sample is shown below.

Thanks you/

Hi NDC,

You can use the following process to achieve the desired calculation.

<< Example >>

(function() {
'use strict';

kintone.events.on(['app.record.create.submit', 'app.record.edit.submit', "app.record.edit.show", 'app.record.detail.show'], function (event) {

var record = event.record;

var sum_bara = 0;
var sum_barb = 0;
var sum_barc = 0;

var tableRecords = record.table.value;

for (var i = 0; i < tableRecords.length; i++) {
var category = tableRecords[i].value.typeab.value;
var price = parseInt(tableRecords[i].value.price1.value);

if (category === "V.I.P"){
sum_bara += price;

} else if (category === "normal"){
sum_barb += price;

} else {
sum_barc += price;

}
}

record.VIP.value = sum_bara;
record.normal.value = sum_barb;
record.blank.value = sum_barc;

return event;
});


})();

There are many ways to write code.
I think it’s better to check the behavior with the example and modify the code to your liking.

By the way, in the example, app.record.detail.show’, even if you return the event object, the value cannot be changed.

Record Details Event:
https://developer.kintone.io/hc/en-us/articles/213149167-Record-Details-Event

Also, you have specified “V.I.P” as the id, but within JavaScript, you need to specify the field code, and “.”(dot) cannot be specified as a field code.

Hi Sean Tachibana,

LUNAR NEW YEAR,

Tks you very much. 

i can did it.