Hi,
I’m trying to capture some of the data in in ‘Orders’ collection transaction (Wix Store) ,as it occur, by using the ‘After Insert’ hook on the ‘Orders’ collection.
My wish is to capture 4-5 fields from the transaction and insert it in to a collection (“order status”) I have created (The field that I need are ‘number’,orderDate, ‘fulfillmentStatus’, ‘paymentStatus’).
I tried to understand wixData and hooks (I’m not experienced with web development) and here what I thought will work in the Hook:
import wixData from ‘wix-data’;
export function Stores$Orders_afterInsert(item, context) {
let CurrenRecord=wixData.currentData;
let toInsert = {
“title”: CurrenRecord(‘number’),
“age”: CurrenRecord(‘_dateCreated’),
“orderStatus”: CurrenRecord(‘fulfillmentStatus’),
“paymentStatus”: CurrenRecord(‘paymentStatus’)
};
wixData.insert(“Order_Management”, toInsert)
.then( (results) => {
let parit = results; //see item below
} )
. catch ( (err) => {
let errorMsg = err;
} );
}
I also tried this:
import wixData from ‘wix-data’;
export function Stores$Orders_afterInsert(item, context) {
let CurrenRecord=wixData.currentData;
let toInsert = {
“title”: item.number,
“age”: item.dateCreated,
“orderStatus”: item.fulfillmentStatus,
“paymentStatus”: item.paymentStatus
};
/let toInsert = {
“title”: CurrenRecord(‘number’),
“age”: CurrenRecord(‘_dateCreated’),
“orderStatus”: CurrenRecord(‘fulfillmentStatus’),
“paymentStatus”: CurrenRecord(‘paymentStatus’)
};;/
wixData.insert(“Order_Management”, toInsert)
.then( (results) => {
let parit = results; //see item below
} )
. catch ( (err) => {
let errorMsg = err;
} )
}
What did I do wrong and how can I debug the code with Chrome dev tools?
Thanks for your effort
ROnen