Help with repeat / split

Hi, I need help with repeat+split macro. I will show you an example as I don't know how to explain it.

Driver list (space separated): {formtext: name=driverlist} {list=filter(split(driverlist, " "), item -> item <> "")}
Zone: {formmenu: default=zone 1; zone 2; zone 3; name=ZONE}

{repeat: for x in list}

{message="Olá! Por favor, dirigir-te para a zona que te foi atribuída para este turno: " }

{=x} {=message} {=ZONE}{endrepeat}

So from the driver list I can get the message to repeat multiple times, but I want to be able to pick different zones for each driver. Is that possible ?

What I mean is it possible for me to change the 2nd one for zone 3 and have the 3rd one zone2 etc.

Hi @LyubomirRadev , welcome to the forum!

Does this work for you?

Driver list (space separated): {formtext: name=driverlist} {list=filter(split(driverlist, " "), item -> item <> "")}

{repeat: for x in list}
Zone for driver "{=x}": {formmenu: default=zone 1; zone 2; zone 3; name=ZONE}
{message="Olá! Por favor, dirigir-te para a zona que te foi atribuída para este turno: " }
{=x} {=message} {=ZONE}{endrepeat}

1 Like

That's perfect. Thanks a lot !

1 Like

Hi @LyubomirRadev

You can even take it a step further:

Driver list: {formmenu: multiple=yes; name=drivers; driver 1; driver 2; driver 3; driver 4}

{repeat: for driver in drivers}
Zone for driver "{=driver}": {formmenu: default=zone 1; zone 2; zone 3; name=ZONE}
{message="Olá! Por favor, dirigir-te para a zona que te foi atribuída para este turno: " }
{=driver} {=message} {=ZONE}{endrepeat}

Or another option:

{note: trim=right}
In the box below, enter the name of the driver, followed by a comma and then the number of the zone.
For multiple drivers/zones, put one entry per line.

For example:
Max, 2
Sasha, 4
Leo, 3
Alex, 1

{formparagraph: name=data; cols=50; rows=5}

{drivers=split(data, "\n")}

{endnote: trim=right}

{=catch(join([split(driver, ",")[1]&" Olá! Por favor, dirigir-te para a zona que te foi atribuída para este turno: Zone "&split(driver, ",")[2] for driver in drivers], "\n\n"), "")}

Additionally, if you have a spreadsheet with names in column A and zones in column B, you could highlight and copy the data to your computer's clipboard, and then use it with the snippet below.

The forum doesn't allow previews of the {clipboard} command, but if you copy the snippet below to your dashboard it will work as explained.

{note: trim=right}
{drivers=split({clipboard}, "\n")}

{endnote: trim=right}

{=catch(join([split(driver, "\t")[1]&" Olá! Por favor, dirigir-te para a zona que te foi atribuída para este turno: Zone "&split(driver, "\t")[2] for driver in drivers], "\n\n"), "")}

You can see a similar example here:

GIF - Clipboard Manipulation

And here's how to copy dynamic snippets from the forum to your dashboard:

GIF - Copy Snippets to Text Blaze

2 Likes

That's an interesting take, as I do have a Google sheet with the data needed. Thanks for the help.

{note: trim=right}
{drivers=split({clipboard}, "\n")}

{endnote: trim=right}

{=catch(join([split(driver, "\t")[1]&" Olá! Por favor, dirigir-te para a zona que te foi atribuída para este turno: Zone "&split(driver, "\t")[2] for driver in drivers], "\n\n"), "")}

This is very cool, but the problem I am having with it is the fact i need to be able to use {urlsend} for each sentence. And I can't get the {urlsend to repeat beneath each row. Is there a way to make that work ?

You can extract a list from the clipboard instead of text, like so:

{note}
n the box below, enter the name of the driver, followed by a comma and then the number of the zone.
For multiple drivers/zones, put one entry per line.

For example:
Max, 2
Sasha, 4
Leo, 3
Alex, 1

{formparagraph: name=data; cols=50; rows=5}

{drivers=split(data, "\n")}

{endnote: trim=right}
{result=catch([[split(driver, ",")[1]," Olá! Por favor, dirigir-te para a zona que te foi atribuída para este turno: Zone ",split(driver, ",")[2]] for driver in drivers], "")}
{=result}

Now, you can use {repeat} on this list and use the zone value as you wish:

{note}
{formparagraph: name=data; cols=50; rows=5}
{drivers=split(data, "\n")}
{endnote: trim=right}
{result=catch([[split(driver, ",")[1]," Olá! Por favor, dirigir-te para a zona que te foi atribuída para este turno: Zone ",split(driver, ",")[2]] for driver in drivers], "")}
{repeat: for value in result}
{drivername=value[1]}
{zone=value[3]} Zone value is {=zone} for driver {=drivername}
{endrepeat}