Hi
My colleague gave me a task that I want to be able to type text in Lookup like a text box and be able to save without any errors.
(function() {
'use strict';
const lookupFieldCode = 'Lookup';
kintone.events.on(['app.record.create.submit', 'app.record.edit.submit'], async function(event) {
event.preventDefault();
const record = event.record;
const submitData = {
app: kintone.app.getId(),
id: record['$id']?.value,
record: record,
};
try {
const apiMethod = event.type === 'app.record.create.submit' ? 'POST' : 'PUT';
const apiURL = kintone.api.url('/k/v1/record', true);
const response = await kintone.api(apiURL, apiMethod, submitData);
if (apiMethod === 'POST') {
console.log('âś… Record added to App');
} else {
console.log('âś… Record updated in App');
}
event.record['$id'] = {value: response.id}
} catch (error) {
console.error('❌ Error saving record:', error);
alert('error: ' + error.message);
}
return event;
});
})();