I built an employee survey satisfaction application in Power Apps a few days ago. This application allows anonymous surveys from employees; here, I was required to convert the current user’s email address to an anonymous email.
So, in this article, I will explain how to replace current user email with anonymous email in Power Apps with a simple scenario.
Replace Current User Email With Anonymous Email in Power Apps
Look at the example below in the employee survey app.
When I toggle on the Is Anonymous Employee in the survey form, the characters before @ from the email in the email field are converted to stars. Again, when I toggled off, it displayed the current user’s email. Clicking the save button in the SharePoint list saves the current user’s email only, even if the displayed email is anonymous.
Follow the steps below to achieve this!
1. Add the code below on the OnStart property of the App object to convert the current user email into anonymous.
Set(AnonymousEmail,Concat(ForAll(Sequence(Find("@",User().Email)-1),"*"),Value)&Mid(User().Email,Find("@",User().Email)));
Here,
- User().Email = Returns current user email address.
- Find() function = Returns the index position of @ in the current user email address.
- Sequence () function = Generates a series of numbers in a single-column table. [The formula subtracts one from the find() function output.]
- Example: Email =PattiF@szg52.onmicrosoft.com
- Find() = Returns 7 [@ position].
- Sequence(7-1)= 6. It generates values from 1 to 6 in the table. like 1,2,3,4,5,6.
- ForAll() function = Converts each number in the table into * star. Which means the table contains six stars.
- Concat() function = It takes each star from the table and converts it into a single text. like ‘******’
- Now, we converted the characters before @ in the email to stars. Let’s see how to combine this star text with the remaining.
- Mid() function = Extracts the text from the given position in the main text. Here, within this function, find() returns @ position in the mail.
- Example,
- Email =PattiF@szg52.onmicrosoft.com
- Find = 7
- Mid() = @szg52.onmicrosoft.com
- & operator concatenates the Concat() output and Mid() output. ******@szg52.onmicrosoft.com
- So, the final email is stored in the AnonymousEmail variable.
2. Then, provide the below code to the Default property of the email text field.
If(tgl_IsAnonymousEmployee.Value, AnonymousEmail, User().Email)
When the toggle value is true, it displays the anonymous email; if not, it shows the current user email.
tgl_IsAnonymousEmployee is the toggle control name.
3. While saving the form details, if you want to store the current user email, even if it is an anonymous survey, add the code below to the Update property of the email datacard in the form.
User().Email
4. To submit the form details, provide the below code on the submit button.
SubmitForm(Frm_EmpSurvey)
Frm_EmpSurvey is the form name, and the SubmitForm() function submits the Power Apps form data to the SharePoint list.
Now, save and publish the app before previewing the Run the OnStart property of the App object.
I hope you understand how to convert the characters in the email into stars and make it anonymous. This approach will be helpful when you must make the emails into anonymous emails.
Also, you may like:
- Power Apps Canvas App Dashboard
- 9 Useful Power Apps Form Validations Examples
- Power Apps Login Page Forgot Password Feature
- Add Custom Logo And Themes in Power Apps
- Show the Current Logged In User in a Combo Box On a Power Apps Modern Form
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com