Unable to get trigger email working at all

Question:
Unable to get trigger emails working at all

Product:
WixEditor/Velo
What are you trying to achieve:
[Explain the details of what you are trying to achieve. The more details you provide, the easier it is to understand what you need.]

What have you already tried:
Multiple walkthroughs and instruction guides

Additional information:
I constantly get the error the following error:

email error Not Found: the requested item no longer exists.

Item exists in dataset:

Logs from running in preview:

succesful save of site member in dataset
member exists, send email
email error Not Found: the requested item no longer exists.

Trigger email snippet:

triggeredEmails.emailMember('Enquire', <enter-member-id-here>, {
  variables: {
        email: <enter-value-here>,
        SITE_URL: <enter-value-here>
  }
});

My code snippet:

import { triggeredEmails } from "wix-crm-frontend";
import { currentMember } from "wix-members-frontend";

$w.onReady(function () {
    $w("#submit").onClick(async () => {
        $w("#siteMembersConnect").onAfterSave(async () => {
            console.log('succesful save of site member in dataset')
            const member = await currentMember.getMember();
            if (member) {
                console.log('member exists, send email')
                const userId = member._id;
                triggeredEmails
                    .emailMember("Enquire", userId, {
                        variables: {
                            email: $w("#email").value,
                        },
                    })
                    .then(() => {
                        console.log('email sent')
                    })
                    .catch((err) => {
                        console.error('email error', err)
                    });
            }
        });
    });
});

Hi, user3542 !!

Is that email address correct? It seems to be missing the “@” symbol. :thinking:

Out of curiosity, do you have your Submit button connected to a dataset?

If yes, then you cannot add code in the code panel to trigger anything onClick. You either code the button OR connect the button but not both.

Also, onAfterSave is not triggered by a button click. It is triggered after a dataset gets saved. So move it out of the “onclick” button code you currently have it under.

And lastly, the variable for the email input is set to the email input value. Any input that is connected via a dataset will erase itself after a dataset saves itself—— that means the value will be empty. So you need to create a variable of the item that was saved and retrieve the email value to insert it into your variables section.

Sorry that was an older screenshot from testing, but the wrong one in, the @ symbol is present

Amazing thank you for the feedback, i’ll double check those solutions later today and see how we get on :+1: