[SOLVED] events.js - wixEvents_onRsvpCreated - Not Working

Hi, I’m trying to insert the event data into a separate database whenever the rsvp form is completed. I’m using the backend function wixEvents_onRsvpCreated in the events.js file located under backend tab. As I understand it backend events are not fired during preview so I’m publishing the site and testing it in live.
The code is really very simple:-

import wixData from 'wix-data';

export function onRsvpCreated(rsvp) {
  let toSave = {
    "rsvpId":        rsvp.rsvpId,
    "eventId":       rsvp.eventId,
    "totalGuests":   rsvp.guests.length,
  }

  wixData.save("eventStatistics", toSave)
    .then( (results) => {
      let item = results;
    } )
    .catch( (err) => {
      let errorMsg = err;
      console.error(errorMsg);
    } );
  }

but as far as I can tell it isn’t firing.
As usual I expect I’m making a simple error or I’ve got completely the wrong end of the stick! Your help would be gratefully received.

As ever it was a simple error. All I had to do was prefix onRsvpCreated with wixEvents_
I followed the advice in the Velo Backend Events Article and created the functions to allow it to be tested. I need to a bit more research as adding an RSVP from the dashboard is triggering two calls of the function but it’s definitely progress :slight_smile:

1 Like