Hi
Anyone that could possibly point me in the right direction your help will be very much appreciated. I have never posted before so hopefully I don’t break any etiquette or rule it won’t be intentional.
I have a form I created which I wish to alter the date format and add an incremental booking number for each booking made before insert to the collection called contactForm. I can get the hook to work fine when the item is put outside the results query. All works and returns amended ok. (I have to hard code the booking value though as I need to fetch the last number to add on the value to pass it back from the hook from inside the results query of the collection, I cannot share the value outside the IF statement.
However I just get this message:
[“Hook beforeInsert for collection contactForm result ignored! Expected hook result to resolve to an object, but got [Undefined]”//
Obviously, I am being daft, and I am not a good programmer. However, it seems frustratingly correct to me and have tried reading and changing loads of things I keep coming back to I must be close as it works if I hard code the value for the bookingNumber outside the query to the collection.
Thanks for reading and help would be a big help to me.
Coz
…
// Convert text date from dropdown Wed Jul 28 1993 14:39 selection to database date format Jul 28 1993 14:39 add incremental booking number.//
import wixData from ‘wix-data’
export function contactForm_beforeInsert(item, context) {
//Hook data.js to intercept incall booking and add numerc date format into databese.
//Additionally add in a running uniquie booking nuber incremetally into databse with each booking adding one tolast record//
import wixData from ‘wix-data’ ;
export function contactForm_beforeInsert(item, context) {
// Convert text date from dropdown Wed Jul 28 1993 14:39 selcetion to databse date format Jul 28 1993 14:39
item.bookingDateTime = **new** Date(item.dropdownField);
console.log( "indside if statment all works :" ,item.bookingDateTime); //works as expected //
wixData.query( "contactForm" ,item)
.gt( 'bookingNumber' , 0 )
.limit( 1 )
.find()
.then ((results) => {
item.bookingNumber = results.items[ 0 ].bookingNumber ++;
console.log( "indside if statement all works : " , item.bookingNumber); //works as expected //
return (item); // [“Hook beforeInsert for collection contactForm result ignored! Expected hook result to resolve to an object, but got [Undefined]”//
})
. catch ( (err) => {
let errorMsg = err;
console.log( "Hook error in booking form: " ,err);
}
)
console.log( "item.bookingNumber : ", item.bookingNumber); // show as null as out IF statement //
console.log( “indside if statement all works :” ,item.bookingDateTime); //works as expected //
return (item)
// [“Hook beforeInsert for collection contactForm result ignored! Expected hook result to resolve to an object, but got [Undefined]”//
}