cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
thunter
Level 8

Email List Box Selected Items

I am trying to email a Form that has a few List Boxes. I am trying to figure out how to email all the Selected Items from each List Box. I ahve tried List.Selected.Value and also List.SelectedItems.Value. When I use Selected, it just sends one of the selected items. When I use SelectedItems, it gives me a red squiggly error line "Invalid Argument Type" . Thanks for your help!

2 ACCEPTED SOLUTIONS

Accepted Solutions
TimRohr
Level 10

Re: Email List Box Selected Items

Look at the Concat() function. It will concatenate across a table (which your SelectedItems is). If your Listbox was named Listbox1 and you wanted a comma-delimited list, you could use:

 

Concat(ListBox1.SelectedItems.Value, Text(Value) & ", ")

NOTE: That would leave you a trailing comma-space at the end, but you can get rid of that with a Left(...,Len(...)-2). For instance, apply the Concat to a context variable, then strip the comma-space off with the Left(,Len()-2) construction.

 

 

ALSO BE AWARE: ForAll() can also come in handy if you want to step over your entries. For instance, if you wanted to send individual emails to different recipients with customized messages. Also keep in mind Collect() as a way to get the Listbox selecteditems in a state where you can perform more complex operations on them.

TimRohr
Level 10

Re: Email List Box Selected Items

First, yes, you want that whole statement. It's basically a Left( thing, Len(thing)-1) construction.

 

Second, you're going to have to build it out from the inside out. Do this to really understand where all the pieces are coming from:

 

1) In the OnChange event of the ListBox, tell it to update a Context variable with the Concat() output.

UpdateContext({mySel: Concat(ListBox1.SelectedItems.myThat,Concatenate(myThat, ","))})

Like I said, "Value" might not work. You might have to choose a field name. In the example, above, I had a ListBox showing records that had two fields (myThis and myThat), with only myThat being displayed.

 

2) Add a label to the screen and assign its Text property to be the context variable you just created.

mySel

3) If you get that to work properly, you're 90% home. Just wrap either the formula or the context variable in a Left(...,Len()-1) statement to strip off the comma:

Left( mySel, Len( mySel) - 1)

Once you get it that far, you can either just leave the context variable updating in the ListBox controls and then reference the variables in your Update property, or you can move the formulas that construct the appropriate string of text into the Update property, themselves.

 

 

13 REPLIES 13
TimRohr
Level 10

Re: Email List Box Selected Items

Look at the Concat() function. It will concatenate across a table (which your SelectedItems is). If your Listbox was named Listbox1 and you wanted a comma-delimited list, you could use:

 

Concat(ListBox1.SelectedItems.Value, Text(Value) & ", ")

NOTE: That would leave you a trailing comma-space at the end, but you can get rid of that with a Left(...,Len(...)-2). For instance, apply the Concat to a context variable, then strip the comma-space off with the Left(,Len()-2) construction.

 

 

ALSO BE AWARE: ForAll() can also come in handy if you want to step over your entries. For instance, if you wanted to send individual emails to different recipients with customized messages. Also keep in mind Collect() as a way to get the Listbox selecteditems in a state where you can perform more complex operations on them.

thunter
Level 8

Re: Email List Box Selected Items

@TimRohr

 

Thanks for your help. The Concat function worked for showing multiple Selected Items in my email, however, when the form is submitted, the Excel spreadsheet only updates one Item instead of all Selected Items.

image1.jpg

TimRohr
Level 10

Re: Email List Box Selected Items

The behavior of the fields and the form on "Submit" is separate from the Concat() operations you were doing for your email. How those fields get saved (or not) will have to do with the type of control in the datacard of the form, the type of field you're writing to (in this case, an Excel source), and the properties of the control & datacard.

 

Can you post some of the above info for your setup?

thunter
Level 8

Re: Email List Box Selected Items

@TimRohr

Which information do you need?

TimRohr
Level 10

Re: Email List Box Selected Items

What is the Update property of the datacard for one of these listboxes?

 

And in what format are you looking to save them? multiple entries in the same cell in Excel? Or as a concatenated list delimited by line breaks or commas?

TimRohr
Level 10

Re: Email List Box Selected Items

thunter
Level 8

Re: Email List Box Selected Items

Update = NameValue.Text

 

I want the selected items in the same cell, seperated by comma is fine

TimRohr
Level 10

Re: Email List Box Selected Items

Yep. You're only going to catch 1 value out of the multiple selections you might have made. Per the post I linked to, you're going to want to do something like:

 

Left(Concat(NameValue.SelectedItems.Value,Concatenate(Text(Value),",")), 
Len(Concat(NameValue.SelectedItems.Value,Concatenate(Text(Value)))-1)

The stuff in orange might change for your particular implementation (instead of Value you might have to reference a particular field).

thunter
Level 8

Re: Email List Box Selected Items

@TimRohr

 

Do I put both these lines in the Update property?

Left(Concat(NameValue.SelectedItems.Value,Concatenate(Text(Value),",")), 
Len(Concat(NameValue.SelectedItems.Value,Concatenate(Text(Value)))-1)

 

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

SecondImage

Follow PowerApps on Twitter

Stay Up-to-Date by following PowerApps on Twitter

Top Community Contributors for July 2019

Top Community Contributors for July 2019

Let's thank our top community contributors

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

FifthImage

Dynamics 365 and Power Platform April 2019 Release notes

Features releasing from April 2019 through September 2019!

Users Online
Currently online: 154 members 4,092 guests
Recent signins:
Please welcome our newest community members: