How to use repeater data outwidth the scope?

Hi Team,

I was wondering if anyone could shed some light on how to allow me to get each Item on a string out width the repeater scope?

let namesNSizes;
    $w('#repeaterPart').forEachItem(($item, itemData) => {
 let  names = $item('#inPName').value;
 let  sizes = $item('#shoeSize').value;
       namesNSizes = names + " size - " + sizes;
       console.log("Inside Rptr - " + namesNSizes)
    });
       console.log("Outside Rptr - " + namesNSizes)

If I enter 2 sets of details via the repeater, it returns as expected within the scope… but out width the scope only the last entry, in this case ‘Terry size - 2’

Any ideas?

What exactly are you trying to accomplish?

Hi @yisrael-wix , thanks for getting back to me.

What I’m trying to achieve is to use the data to send in a dynamic template via SendGrid. I have everything working but this last variable.

The issue is that the user could select between 1 - 8 people and I want to capture each item #name and #shoesize if they have selected the #checkbox then use it in a string to send to the template variable. All of the element are within the repeater.

i.e. the user selects one and ‘check’ the checkbox for boots then it would show something like

name1 - size 7

is they select three participants and ‘check’ for everyone for boots

name1 - size 7
name2 - size 3
name3 - size 12

if they select three participants but only ‘check’ two people

name1 - size 7
name3 - size 12

and so on.

I can get the results I’m looking for but only within the scope of the repeater…

Many thanks in advance!

Stephen

@stephenmccall Take a look at Retrieve Repeater Item Data When Clicked which will explain exactly what you need to do, and has the code snippets that you’ll need.

mmm… I couldn’t get this to work but I found a solution I think. It seems to work

$w('#repeaterPart').forEachItem(($item) => {
 let namesNSizes;
 if($item('#shoesCheckBox').checked){
 let names = validate($item("#inPName").value);
 let shoes = validate($item("#shoeSize").value);
        namesNSizes = names + " - " + shoes
        }
        bootHireEmail(name, title, date, duration, bootHireNbr, namesNSizes)
            .then(() => {
 let dataObj = {
                 status: 'Boot Hire Success!',
                };
                console.log(dataObj)
            })
            .catch((error) => {
 let dataObj = {
                status: 'Boot Hire Fail!',
                };
                console.log(dataObj)
            });
    });



function validate(value) {
 if (value) return value
 return " - "
}

I’ll see if any problems occur during testing!

Thanks for your help.

Scrap that! Back to the drawing board…

Hi @yisrael-wix I seem to be so close but can’t get the final display as it seems to be showing an array on the sendGrid form. Would you be able to help?

function bootHire() {
 var email = $w('#email').value;
 let participants = $w('#participants').value;
 let name = $w('#fullname').value;
 let date = $w('#coursestartdatetxt').value;
 var mergeTags = {};

    $w('#repeaterPart').forEachItem(($item, itemData, i) => {
 if ($item('#shoesCheckBox').checked) {
             mergeTags ["Participant " + (i +1)] = validate($item("#inPName").value) + " • Size - " + validate ($item('#shoeSize').value) + "<BR>";
 
        }
    });
 
 var myJSON = JSON.stringify(mergeTags);
 
 return bootHireEmail(name, title, date, duration, bootHireNbr, myJSON)
            .then(() => {
 let dataObj = {
                    status: 'Boot Hire Success!',
                };
                console.log(dataObj)
            })
            .catch((error) => {
 let dataObj = {
                    status: 'Boot Hire Fail!',
                };
                console.log(dataObj)
            });

}

The template showing the values via sendGrid

If you were able to help me it would be much appreciated :slight_smile: