How to press save even if the Lookup has data that does not match the original app


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;
    });
})();

Hello @Master_Over_Sun
I don’t think it’s possible to prevent these errors from occurring or displaying, as they’re part of Kintone’s built-in validation process for Lookup fields.

The only workaround I can think of would be to replace the Lookup field with a text field and implement a custom lookup logic using the REST API via JavaScript.

2 Likes