I have a simple one page site with one button, and a dataset linked to a database; and a table linked to that dataset: peterjanderson6724.wixsite.com/website-1 . Try it.
The page code is:
import wixData from 'wix-data';
$w.onReady(function () {
$w("#dataset1").onReady(() => {
$w('#table1').refresh()
});
});
export function writeTestData_click(event) {
let dateNow = new Date()
let toInsert = {
"testField": 'AAAA',
'comment': 'Test Insert',
'testDateText': dateNow.toString()
};
wixData.insert("TestData", toInsert)
.then((results2) => {
$w('#dataset1').refresh()
console.log('INSERT SUCCESS', results2);
})
.catch((err) => {
let errorMsg = err;
console.log('INSERT FAIL', errorMsg);
})
}
and there is a hook on the database ‘TestData’ as follows:
export function TestData_beforeInsert(item, context) {
item.testField = 'BBBB'
console.log('Data hook fired', item)
return item;
}
So what I expect to happen is that the page code inserts an item into the database with testField set to ‘AAAA’, and the hook changes the value of testField to 'BBBB.
This works fine in Preview, where all items in the database are written with testField value ‘BBBB’.
But on the live site all items in the database have testField value ‘AAAA’.
Why is the hook not firing on the live site?
Where am I going wrong?