I'm trying to extract data from a table to put into a field outside the table in Kintone. I've read and noticed that the native plug-ins, etc. will not perform this so I was looking into coding as an option but to be honest, I'm a noob at best with JS coding. Any suggestions on where I could find some examples or knowledge on pulling data from a table to placing in a field outside the table?
My Table contains a container type, volume, comment. When the container type TOTE is selected, I need the volume associated with the TOTE row to be place in another field that is outside the table BUT in the same app.
At first, I thought using a simple if statement with a CONTAIN function in a calculation or text field (I tried both) will do the trick but it doesn't like it.
Any assistance would be greatly appreciated. Thank you.
Thank you.
There will only be one row with TOTE. Won't have to worry about multiple rows with the same type. I'm using tables because the plant that will be using this app may have to enter different types of containers for the same new product or product change. The Container type is a drop down that allows them to select. the type, example we have TOTE, DRUM, PAIL, BIB, etc.
For each type there will be a volume amount(gallons) that they will have to enter (number field) and a Comment if needed (text area) field
Hello @dpoetsch
I apologize for the delay, I don't know why but I didn't get any notification.
Below is a script that functions as you described. Feel free to use it as a reference:
(function() {
'use strict';
var SUBTABLE_CODE = 'Table'; // Subtable field code
var DROPDOWN_FIELD = 'Dropdown'; // Dropdown field within the subtable
var NUMBER_FIELD_INSIDE = 'Number'; // Number field inside the subtable
var NUMBER_FIELD_OUTSIDE = 'Number1'; // Number field outside the subtable
// Listen to changes in both the Dropdown and Number fields within the subtable
var dropdownEvents = [
'app.record.edit.change.' + DROPDOWN_FIELD,
'app.record.create.change.' + DROPDOWN_FIELD
];
var numberEvents = [
'app.record.edit.change.' + NUMBER_FIELD_INSIDE,
'app.record.create.change.' + NUMBER_FIELD_INSIDE
];
kintone.events.on(dropdownEvents.concat(numberEvents), function(event) {
var record = event.record;
var subtables = record[SUBTABLE_CODE].value;
// Initially set Number1 to empty if TOTE is not selected
record[NUMBER_FIELD_OUTSIDE].value = ""; // Clear the outside field first
subtables.forEach(function(row) {
if (row.value[DROPDOWN_FIELD].value === 'TOTE') {
record[NUMBER_FIELD_OUTSIDE].value = row.value[NUMBER_FIELD_INSIDE].value;
}
});
return event;
});
// Disable the Number1 field on form show events
var formShowEvents = [
'app.record.create.show',
'app.record.edit.show',
'app.record.detail.show'
];
kintone.events.on(formShowEvents, function(event) {
event.record[NUMBER_FIELD_OUTSIDE].disabled = true;
return event;
});
})();
HI @Chris, this worked perfectly, excatly what I needed. Thank you for the code/lesson. I have put it in my folder of learned code ideas. Thanks again!