Hello again,
First, we should be updating the row instead of inserting again, it has similar syntax:
let toUpdate = {
"_id": id,
"newdateAsSt": formatdate
};
wixData.update("myCollection", toUpdate)
.then( (results) => { let item = results; //see item below
})
.catch( (err) => { let errorMsg = err;
});
Next, we need to figure out why the id is returning undefined. Try making it a global variable outside the .afterInsert() hook.
Best,
Majd