Usecase: OnInvoiceSent trigger → email customer with history of payments for an invoice.
Below code works
export async function InvoiceSent ( event ){
console . log ( “InvoiceSent” , event );
//console.log(event.data.payments[0].type);
if ( event . data . payments . payments . length > 0 && event . data . payments . payments . length <= 50 ){
var paymentHistory = “Dear " + event . data . customer . name + “, Your payment history for Invoice no:” + event . data . number + " is below%0A” ;
event . data . payments . payments . forEach ( element => {
//console.log(element);
paymentHistory = paymentHistory + "%0A%0APayment ID: " + element . id + ".%0APayment Date: " + new Date ( element . date ). toLocaleDateString ( “en-IN” , { timeZone : ‘Asia/Kolkata’ }) + “%0AAmount Rs.” + element . amount . serializedValue ;
});
console . log ( paymentHistory );
}
}
after adding below code the entire event system is crashed and no events are logged in the system
import { triggeredEmails } from ‘wix-crm’;
//…
triggeredEmails.emailContact(‘123456’, , {
variables: {
invoiceNumber: ,
clinicName: ,
customerName: ,
invoiceNumberSub: ,
paymentHistory:
}
});