Cannot read property 'iD' of null

I had to recreate a website after my original website crashed I am doing a senior seminar project and have a custom form anyone can input credentials. I am having an error with my code that will compare the input from my custom form to a static collection.

import wixData from ‘wix-data’;

export function sIn_beforeInsert(item) {

return wixData.query('registry')
    .eq('idv', item.iD)
    .find()
    .then(results => {
        if (results.items.length > 0) {
             const hotelMSData = {
                fNamec: fN,
                lNamec: lN,
                idvc: item.iD

            };
            wixData.insert('HMS', hotelMSData);
        }
    })
    .catch(err => {
        console.error(err);
    });

}

getting cannot read property iD of null.

Hi Calena

You have to use item._id

(The “d” has to be lowercase)

1 Like

It might also be item._id as that’s typically the column where the id is stored for an item in a collection.

image
This is the field for my form

Ah ok that makes things a bit clearer.

The mistake is in this line

return wixData.query('registry')

it should be:

return wixData.query('scanIn')

Are you trying to use iD in the scanln collection, or iD in the sln item that is being inserted?