Hello,
I have an inserted line with a field named “from” in a dataset A
My requirement is to fill another field named “fromOACI” in the same dataset A from another dataset B
Dataset A:
Dataset B:
I want the hook after insert be able to populate automatically the field “fromOACI” from the Dataset A.
In my example I am expecting the field fromOACI to get the value “LECO”
Unfortunately this is not working, I get the error:
Hook afterInsert for collection flightDataset result ignored! Expected hook result to resolve to an object with an ‘_id’ property, but got [Undefined]
Thanks for your help.
Regards,
Pym
export function flightDataset_afterInsert(item, context) {
…
wixData.query(“airportDataset”) // airportDataset = Dataset B
.eq(“airportName”, item.from)
.find()
.then((results) => {
let toUpdate = {
“_id”: item._id,
“fromOACI”: results[0].oaci
};
wixData.update(“flightDataset”, toUpdate) // flightDataset = Dataset A
})
.catch((err) => {
let errorMsg = err;
console.log(errorMsg);
});