cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
powerapps890
Post Prodigy
Post Prodigy

Email form based on datacard value

Office365Outlook.SendEmailV2("myemail", Form1.LastSubmit.ReqID &" - "& Form1.LastSubmit.Title&":", "<a href='https://apps.powerapps.com/play/04184d60-38af-480b-91cf-e7369b2b5188?tenantId=5dbf1add-202a-4b8d-815..." & Form1.LastSubmit.ID & "'> Click to view the CR</a> "); This is in the onsuccess of my form.

I want to alter it so that depending on a certain data card value the email is submitted to different people. So for example if one of the datacard values is favorite color blue send it to that user that submitted it and sue. If they choose their favorite color as red send it to that user and dan. So I always want the person submitting to get an email with their form, but then I also want certain people to get it based on the datacard value. Is this possible.

18 REPLIES 18
RandyHayes
Super User III
Super User III

@powerapps890 

Yes, the control type in the datacard is not relevant in this case - you are saying that the underlying datacolumn "FavoriteColor" is a text column. 

Therefore, Form1.LastSubmit.FavoriteColor will be a text value.  AND, I also assume that your Update property on the DataCard for FavoriteColor is set to return a Text value.

 

When you put your cursor right after the FavoriteColor in the formula, what data type does the formula editor tell you it is?  It should be Text.

Office365Outlook.SendEmailV2(
    "myemail" & 
    Switch(Form1.LastSubmit.FavoriteColor,
        "blue", "; sue@mycompany.com",
        "red", "; dan@mycompany.com"
    ), 
    Form1.LastSubmit.ReqID & " - " & Form1.LastSubmit.Title & ":", 
    "<a href='https://apps.powerapps.com/play/04184d60-38af-480b-91cf-e7369b2b5188?tenantId=5dbf1add-202a-4b8d-815..." & Form1.LastSubmit.ID & "'> Click to view the CR</a>"
); 

The syntax of the above formula is accurate.  If you are getting the error that you are, then there is something wrong with one of the parameters of the SendEmailV2 function and is thus complaining that there is an error with one of them.  

 

I am pretty sure that you are not using the above formula verbatim and that we are not really dealing with a "Favorite Color" column but some other one that you are working with.  So, if so, make sure that you are substituting your real column names and choice values (the color names) as well as the email addresses (notice the semicolon and then email) properly.

 

I have vetted the above formula in a sample app and it is fully functional.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

View solution in original post

I will show you exactly what I have. Capture.PNG

Contacts and Products spelled exactly like that are two of the options in the process step dropdown menu. All of the syntax is the same as yours. @RandyHayes Yes, it is a text type when I hover over it.

RandyHayes
Super User III
Super User III

@powerapps890 

Perfect!  So the syntax looks good.  Are you getting a red underline on anything in that formula?  If so, where?

And also, when you put the cursor in the formula editor right after Form1.LastSubmit.'Process Step' what Data type does the editor tell you that it is?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

There are no red underlines and it says text @RandyHayes 

RandyHayes
Super User III
Super User III

@powerapps890 

So then where are we?  If there are no underlines and it is text, then the formula looks great.

What happens when you submit a form?  Does it send an email to you and the one listed by the Process Step choices?

Also, you showed that image of the error you were seeing - where was that from?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

The form submitted to the sharepoint list but no email was sent..The error message I showed you was from when I hit submit and it took me back to the app landing page and said that. So the problem is with the email portion. @RandyHayes 

RandyHayes
Super User III
Super User III

@powerapps890 

So, let's troubleshoot a bit then.

 

Place a label on your screen and set the Text property to:

vUserMail & 
Switch(Form1.Updates.'Process Step',
   "Contacts", "; contacts@mycompany.com",
   "Products", "; products@mycompany.com"
)

NOTE: this uses the Updates property, so, you should be able to see the label text change as you change your dropdown selection.

 

See that it is showing a proper semicolon separated email address list.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

It works now the issue was with the link, but now it works perfectly. My last question is will this work with more than 2 emails. For example, I might have a need for about 10 different emails depending on that selection. @RandyHayes 

RandyHayes
Super User III
Super User III

@powerapps890 

Oh thank goodness!!  I was about to start pulling my hair out along with you!

Yes, you can certainly have multiple emails.  My recommendation is that you set this in a variable in your OnStart rather than directly in the formula (this way if you have to change in the future, you don't have to hunt down this formula).

 

Something like this in the OnStart:

Set(AppData, 
    {ContactEmails : "contact1@company.com; contact2@company.com; contact3@company.com",
     ProductEmails : "contact4@company.com; contact5@company.com; contact6@company.com"
    }
)

Then change your OnSuccess formula to the following (plus the fix to your link you found): 

Office365Outlook.SendEmailV2(
    vUserMail & 
    Switch(Form1.LastSubmit.'Process Step',
        "Contacts", "; " & AppData.ContactEmails,
        "Products", "; " & AppData.ProductEmails
    ), 
    Form1.LastSubmit.ReqID & " - " & Form1.LastSubmit.Title & ":", 
    "<a href='https://apps.powerapps.com/play/04184d60-38af-480b-91cf-e7369b2b5188?tenantId=5dbf1add-202a-4b8d-815..." & Form1.LastSubmit.ID & "'> Click to view the CR</a>"
); 

 

Much easier to maintain in the future.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

Top Solution Authors
Top Kudoed Authors
Users online (53,032)