Collection does not exist error

@dean41146

Try this one…

import wixData from 'wix-data';

$w.onReady(function () {});

export function saveForm_click(event) {get_data()}

function get_data() {
 let ID = $w("#clientID").value;

    wixData.query("onboardingForm")
    .eq("_id", ID)
    .find()
    .then((results) => {
 if (results.items.length > 0) {//here the code-part when an itemID was found! (existing already) ---> toUpdate-process
 let firstItem = results.items[0];
            start_UPDATE()
        }
 else { //here the code-part when an itemID was NOT found! (not existing yet) ---> toInsert-process
            start_INSERTION()
        }
    })
    .catch( (err) => {
 let errorMsg = err;
    });
}


function start_UPDATE() {
 let toUpdate = {
 "_id": $w("#clientID").value,
 "clientCoName":     $w("#clientComp").value,
 "firstName":        $w("#clientFirstName").value,
 "lastName":         $w("#clientLastName").value,
 "accountNumber":    $w("#clientAccNum").value,
 "registrationDate": $w("#registrationDate").value,
 "step1":            $w("#step1Complete").checked,
    }
 
    wixData.update("onboardingForm", toUpdate)
    .then( (results) => {
 let item = results;
    })
    .catch( (err) => {
 let errorMsg = err;
    });
}


function start_INSERTION() {
 let toInsert = {
 "clientCoName":     $w("#clientComp").value,
 "firstName":        $w("#clientFirstName").value,
 "lastName":         $w("#clientLastName").value,
 "accountNumber":    $w("#clientAccNum").value,
 "registrationDate": $w("#registrationDate").value,
 "step1":            $w("#step1Complete").checked,
    }

 
    wixData.insert("onboardingForm", toInsert)
    .then( (results) => {
 let item = results;
    })
    .catch( (err) => {
 let errorMsg = err;
    });
}


I did not test it, ao you will perhaps to modify it a little bit to get it to work.

It is not he best solution, you can surely upgrade the code, but this should work.