** Resolved** kinda - SendGrid email with data from a repeater array in body of email

I have a page that displays info in a repeater. It shows a station name and then an evaluation of how a student performed in that station (see picture below). I would like to have a button on that page that sends an email, using SendGrid, to the student with their evaluations. Currently the email works but I can’t figure out how to get the information in the repeater into the body of the email. Right now, the below code is all I’ve been able to get working. The backend files are set up as described in this post: Velo Tutorial: Sending an Email on Form Submission | Help Center | Wix.com

I know I need some kind of loop or an if/then or maybe a when statement… Any help would be greatly appreciated. If you’d like to take a look at the website, here it is https://mrnevitt.wixsite.com/test

Thanks

Code:
import {sendEmail} from ‘backend/email’;

function sendFormData() {
const subject = Here are your evaluations;
const body = Name: Mike \rStation: Test \rEvaluation: test;

sendEmail(subject, body)
.then(response => console.log(response));
}

export function emailButton_click(event, $w) {
//Add your code for this event here:
sendFormData();
}

I’ve even tried pulling an item from the dataset with .getcurrentItem() without any luck. Although I could have been using that incorrectly too.

So I’ve gotten a little farther. I’m able to send an email with the value that is in the text boxes on the repeater. I think there should be a way to do this with something like $w(“#myRepeater”).forEachItem() but I can’t figure out how to get data out of the repeater array . Here is my current code:

input2 is the first name of the student and text20 and 21 or the text boxes in the repeater that are linked to the dataset.

export function emailButton_click(event, $w) {
//Add your code for this event here:
sendFormData();
wixWindow.openLightbox(“Email sent 2”)

function sendFormData() {
const subject = ${$w("#input2").value} here are your evaluations;
const body = \rStation: ${$w("#text20").text} \rEvaluation: ${$w("#text21").text};

sendEmail(subject, body)
.then(response => console.log(response));
}

}

A little more progress… the only issue now is that I get a separate email for each item in the repeater. I would like them all in one email. And I know this is because of where the sendEmail call is but i can’t figure out how to construct the body without doing it this way.

export function emailButton_click(event, $w) {
//Add your code for this event here:
sendFormData();
wixWindow.openLightbox(“Email sent 2”)

function sendFormData() {
const subject = ${$w("#input2").value} here are your evaluations;
$w(‘#repeater1’).forEachItem(($x, itemData, index) => {
let station = itemData.stationName
let evaluation = itemData.studentEvaluation
const body = \rStation: ${station} \rEvaluation: ${evaluation};

        sendEmail(subject, body) 
            .then(response => console.log(response)); 
    }); 

} 

}

I have it working. Put in an if statement and moved the sendEmail call down and I know get an email with all of the repeater data. It’s very plain right now but it works. See code and email example below:

function sendFormData() {
const subject = ${$w("#input2").value} here are your evaluations;
let body = ``;
$w(‘#repeater1’).forEachItem(($x, itemData, index) => {
if (itemData.id !== “”){
let station = itemData.stationName
let evaluation = itemData.studentEvaluation
body = body + \rStation: ${station} \rEvaluation: ${evaluation};
}
});
sendEmail(subject, body)
.then(response => console.log(response));

} 

Hi Mike, I am very interested on this code, but I am not to expert would you please to post the whole piece of code, so I can copy and paste and replace my items I guess… I am trying to use this to let people to send a wish list … Thank you