Hi guys, I been try to lookup the table data from another application. But seems like the lookup function didnt triggered as the picture below.
And I need to click the lookup one by one. So the question ss there any recommended way that I can triggered all the lookup function when I click the Submit function.
This is my Code
jQuery.noConflict();
(function($) {
‘use strict’;
const events2 = [
‘app.record.create.change.Number_1’,
‘app.record.edit.change.Number_1’,
“app.record.create.show”,
“app.record.edit.show”,
“app.record.create.submit”
];
kintone.events.on(events2, function(event) {
kintone.app.record.setFieldShown(‘Number_1’, false);
const targetAppId2 = kintone.app.getLookupTargetAppId(‘Lookup_0’);
const targetRecordId2 = event.record[‘Number_1’].value;
// Empty the table after clearing the lookup
if (!targetRecordId2) {
event.record[‘main_ingre’].value = [];
event.record[‘external_sub_ing’].value = [];
event.record[‘self_sub_ing’].value = [];
return event;
}
const body2 = {
app: targetAppId2,
id: targetRecordId2,
};
console.log(body2);
kintone.api(kintone.api.url(’/k/v1/record’, true), ‘GET’, body2, function(resp) {
event.record[‘main_ingre’].value = resp.record[‘main_ingre’].value;
event.record[‘external_sub_ing’].value = resp.record[‘external_sub_ing’].value;
event.record[‘self_sub_ing’].value = resp.record[‘self_sub_ing’].value;
// When making the subtable uneditable
for(var i = 0; i < event.record[‘production’].value.length ; i++){
if(event.record[‘Lookup_0’].value == event.record[‘production’].value[i].value.Text.value){
event.record[‘main_ingre’].value.forEach(function(obj) {
Object.keys(obj.value).forEach(function(params) {
obj.value[params].disabled = false;
obj.value[‘calculated_quantity’].value = obj.value[‘rm_uprice’].value*event.record[‘production’].value[i].value.quantity.value;
obj.value[‘calculated_quantity’].value = obj.value[‘calculated_quantity’].value.toFixed(2);
});
});
console.log(“true”);
}else{
console.log(“false”);
//event.record[‘production’].value[i].value.quantity.value = resp.record[‘main_ingre’].value[0].value.quantity2.value;
}
}
//return event;
kintone.app.record.set(event);
}, function(err) {
window.alert(‘An error occurred in the REST API’);
});
});
})(jQuery);
Thanks Again