Triggered email send with multiple response (SOLVED)

Hi all,

I am putting code here to help people achieve a IF/ELSE response to a form submission. Below is my example;

Setup a triggered email firstly by following these steps here . When you are done, follow the below steps.

My fields (You can change and tailor to whatever you wish;
Your name = #input1
Your email = #input2
Response (Yes or No) = #radioGroup1
Button Label = button1

Connect your button to your database

Then setup an EVENT onClick;

Then the Code

import wixCRM from 'wix-crm';

$w.onReady(function () {

});

export function button1_click(event, $w) {
 wixCRM.createContact({
 "name": $w('#input1').value,
 "email": [$w("#input2").value],
 "responce": $w("#radioGroup1").value
  })

 if ($w('#radioGroup1').value === 'Yes') {
// here, I want to send a triggered email with the unique email ID "Qy1ReCD"  
                    .then((contactId) => {
                    wixCRM.emailContact("Qy1ReCD", contactId, {
 "variables": {
 "name": $w('#input1').value,
                        }
                        })
                        .then(() => {
 // do something after the email was sent
                        })
                        .catch((err) => {
 // handle the error if the email wasn't sent
                        });
                    });
                    }
else {  // here, I want to send a triggered email with the unique email ID "Qy1K8NW"                 
/ here, I want to send a triggered email with the unique email ID "Qy1K8NW"  
                      .then((contactId) => {
                        wixCRM.emailContact("Qy1K8NW", contactId, {
 "variables": {
 "name": $w('#input1').value,
                        }
                        })
                        .then(() => {
 // do something after the email was sent
                        })
                        .catch((err) => {
 // handle the error if the email wasn't sent
                        });
                    });
}

Hope this helps somebody looking for a if or else response using a triggered email from a form submission.

Cheers,
Conor

PLEASE HELP***

I’ve now be able to submit without any errors on preview, however I’m not getting any triggered emails?
Anyone able to advise where I am going wrong?

import wixCRM from 'wix-crm';

$w.onReady(function () {

});

export function button1_click(event, $w) {
if ($w('#radioGroup1').value === 'Yes') {
    wixCRM.createContact({
 "firstName": $w('#input1').value,
 "emails": [$w("#input2").value],
 "Responce": $w("#radioGroup1").value
  })
  .then((contactId) => {
   wixCRM.emailContact("Qy1ReCD", contactId, {
 "variables": {
 "name": $w('#input1').value,
 "interest_area": $w("#radioGroup1").value
     }
    })
    .then(() => {
 // do something after the email was sent
    })
    .catch((err) => {
 // handle the error if the email wasn't sent
    });
  });
} 

else {
    wixCRM.createContact({
 "firstName": $w('#input1').value,
 "emails": [$w("#input2").value],
 "Responce": $w("#radioGroup1").value
  })
  .then((contactId) => {
   wixCRM.emailContact("Qy1K8NW", contactId, {
 "variables": {
 "name": $w('#input1').value,
 "interest_area": $w("#radioGroup1").value
     }
    })
    .then(() => {
 // do something after the email was sent
    })
    .catch((err) => {
 // handle the error if the email wasn't sent
    });
  });
}}