heiavieh
heiavieh

Reputation: 29

Emailing column values using a collection and ForAll()

Making a powerapps canvas app using Excel tables. It's a check-in/check-out system. If the visitors are in a group, it is supposed to collect all of their information and hold it in a collection until it's ready to be submitted.

When submitted, it's supposed to email the Host, with all the names of the visitors. But I'm having trouble figuring out how to properly show that.

I decided to set a variable for the actual visitor information.

In my OnStart, there is this variable:

Set(varNames, ForAll(VisitorGroup, $"{Name} {Surname}"));

In the OnSelect that I have for the submit button, I have this so far:

Office365Outlook.SendEmailV2(
        choiceHost_1.Selected.Mail,
        If(varContractor = true, "Facility Entrypoint: Returning contractors have arrived on site!", "Facility Entrypoint: A group is here to visit again!"),
        $"{choiceHost_1.Selected.GivenName}, You have multiple visitors. Please make sure they keep the safety guidelines in mind.<br/><br/> Visitors: {varNames}"
    );

When I do this, I get a message that says: "Expressions which appear inside an interpolated string must evaluate to a Text value or to a compatible type." as well as "Invalid argument type (Table). Expecting a Test value instead."

I want to display all of the names separately. This is the desired layout of the email:

Visitors:
First_Name Last_Name
First_Name2 Last_Name2
...

So on and so forth until the collection is done. I'm just not sure how to exactly get there. Any ideas on how I can solve this?

Upvotes: 0

Views: 442

Answers (1)

Farrukh Shah
Farrukh Shah

Reputation: 1

To display the names of visitors separately in your email, you can use the Concatenate function to join the visitor names with line breaks between them. Here's how you can modify your code to achieve the desired layout here is the updated code Office365Outlook.SendEmailV2( choiceHost_1.Selected.Mail, If(varContractor = true, "Facility Entrypoint: Returning contractors have arrived on site!", "Facility Entrypoint: A group is here to visit again!"), $"{choiceHost_1.Selected.GivenName}, You have multiple visitors. Please make sure they keep the safety guidelines in mind.

Visitors:
{Concatenate(varNames, "
")}" ); In the above code, we use the Concatenate function to join the visitor names with
tags between them. This will create a new line for each visitor's name, giving you the desired layout in the email.

Make sure that varNames contains the names of all the visitors in the correct format, and this code should display them as separate lines in the email.

another answer is To achieve the desired layout in your PowerApps email with visitor names displayed separately, you can modify your code as follows:

1: Create a collection to store the visitor names when a group of visitors is checked in. 2: Use a formula to concatenate the visitor names with line breaks. 3: Send the email with the concatenated visitor names. Here's how you can modify your PowerApps code: 1: Create a collection to store visitor names when a group of visitors is checked in:

ClearCollect(VisitorNamesCollection, VisitorGroup);

This assumes that VisitorGroup is a collection that contains the information of the visitors.

2: Use a formula to concatenate the visitor names with line breaks. You can use a combination of the Concat function and Text function:

Set(varVisitorNames, Concat(VisitorNamesCollection, Text(Name & " " & Surname, "[$-en-US]@"), Char(10)));

In this formula:

Concat is used to concatenate the names in the VisitorNamesCollection. Text is used to format the visitor names as text. Char(10) is used to represent a line break. 3: Send the email with the concatenated visitor names:

Office365Outlook.SendEmailV2( choiceHost_1.Selected.Mail, If(varContractor = true, "Facility Entrypoint: Returning contractors have arrived on site!", "Facility Entrypoint: A group is here to visit again!"), $"{choiceHost_1.Selected.GivenName}, You have multiple visitors. Please make sure they keep the safety guidelines in mind.

Visitors:
{varVisitorNames}" );

In the email body, {varVisitorNames} will contain the concatenated visitor names with line breaks, displaying them as you desired:

makefile Visitors: First_Name Last_Name First_Name2 Last_Name2 This should resolve the issue you were facing and display the visitor names separately in the email.

Upvotes: -1

Related Questions